参考1:

https://www.jianshu.com/p/b39d3a17d902
绝对定位
每个程序都是以像素为单位区分元素的位置,衡量元素的大小。所以我们完全可以使用绝对定位搞定每个元素和窗口的位置。但是这也有局限性:

元素不会随着我们更改窗口的位置和大小而变化。
不能适用于不同的平台和不同分辨率的显示器
更改应用字体大小会破坏布局
如果我们决定重构这个应用,需要全部计算一下每个元素的位置和大小

参考2

https://www.jianshu.com/p/b39d3a17d902
如果我们需要把两个按钮放在程序的右下角,创建这样的布局,我们只需要一个水平布局加一个垂直布局的盒子就可以了。再用弹性布局增加一点间隙。
上面的例子完成了在应用的右下角放了两个按钮的需求。当改变窗口大小的时候,它们能依然保持在相对的位置。

#!/usr/bin/python3
# -*- coding: utf-8 -*-"""
ZetCode PyQt5 tutorial In this example, we position two push
buttons in the bottom-right corner
of the window. Author: Jan Bodnar
Website: zetcode.com
Last edited: August 2017
"""import sys
from PyQt5.QtWidgets import (QWidget, QPushButton, QHBoxLayout, QVBoxLayout, QApplication)class Example(QWidget):def __init__(self):super().__init__()self.initUI()def initUI(self):okButton = QPushButton("OK")cancelButton = QPushButton("Cancel")hbox = QHBoxLayout()hbox.addStretch(1)hbox.addWidget(okButton)hbox.addWidget(cancelButton)vbox = QVBoxLayout()vbox.addStretch(1)vbox.addLayout(hbox)self.setLayout(vbox)    self.setGeometry(300, 300, 300, 150)self.setWindowTitle('Buttons')    self.show()if __name__ == '__main__':app = QApplication(sys.argv)ex = Example()sys.exit(app.exec_())

参考3

https://zhuanlan.zhihu.com/p/64574283
https://github.com/luochang212/pyqt5-demo/blob/master/Demo/praise_me_please.py

main_layout.setStretch(0, 1)表示0号部件的拉伸设置为1
main_layout.setStretch(1, 3)`表示1号部件的拉伸设置为3

参考4:

https://www.cnblogs.com/laizhenghong2012/p/10040798.html

绝对布局的缺点:

如果改变一个窗口的大小,窗口中控件的大小和位置不会随之改变
所生成的窗口在不同的操作系统下看起来可能不一样
在程序中改变字体时可能会破坏布局
如果修改布局,比如新增一个控件,就必须全部重新布局,既烦琐又费时

对齐方式Qt.Alignment可能取值有:

addWidget(self, QWidget, stretch, Qt.Alignment alignment) 在布局中添加控件,stretch为伸缩量,alignment为对齐方式
参数 描述
Qt.AlignLeft 水平居左对齐
Qt.AlignRight 水平居右对齐
Qt.AlignCenter 水平居中对齐
Qt.AlignJustify 水平两端对齐
Qt.AlignTop 垂直靠上对齐
Qt.AlignBottom 垂直靠下对齐
Qt.AlignVCenter 垂直居中对齐

#!/usr/bin/env python3
# -*- coding: utf-8 -*-import sys
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QWidget, QPushButton, QHBoxLayout, QApplicationclass Window(QWidget):def __init__(self):super().__init__()hbox = QHBoxLayout()hbox.addWidget(QPushButton(str(1)), 0, Qt.AlignTop)hbox.addWidget(QPushButton(str(2)), 0, Qt.AlignTop | Qt.AlignLeft)hbox.addWidget(QPushButton(str(3)), 0)hbox.addWidget(QPushButton(str(4)), 0, Qt.AlignLeft | Qt.AlignBottom)hbox.addWidget(QPushButton(str(5)), 0, Qt.AlignTop)self.setLayout(hbox)self.setWindowTitle('水平布局')self.show()if __name__ == '__main__':app = QApplication(sys.argv)w = Window()sys.exit(app.exec_())

参考5 :

https://blog.51cto.com/9291927/2423303
https://blog.51cto.com/9291927/2423303
PyQt5快速入门(五)PyQt5布局管理

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QHBoxLayout, QPushButton, QSizePolicyclass MainWindow(QWidget):def __init__(self, parent=None):super().__init__(parent)self.layout = QVBoxLayout()self.layout.setSpacing(20)# 第一行按钮布局管理hLayout1 = QHBoxLayout()button = QPushButton("Button1")button.setMinimumSize(60, 30)button.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)hLayout1.addWidget(button)button = QPushButton("Button2")button.setMinimumSize(60, 30)button.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)hLayout1.addWidget(button)# 第二行按钮布局管理hLayout2 = QHBoxLayout()button = QPushButton("Button1")button.setMinimumSize(60, 30)button.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)hLayout2.addWidget(button)button = QPushButton("Button2")button.setMinimumSize(60, 30)button.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)hLayout2.addWidget(button)# 整体垂直布局管理self.layout.addLayout(hLayout1)self.layout.addLayout(hLayout2)self.setLayout(self.layout)if __name__ == "__main__":app = QApplication(sys.argv)window = MainWindow()window.resize(400, 200)window.show()sys.exit(app.exec_())

pyqt5 中文教程

http://code.py40.com/pyqt5/18.html

参考7

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QHBoxLayout, QPushButton
from PyQt5.QtCore import Qt
class Winform(QWidget):
def init(self, parent=None):
super(Winform,self).init(parent)
self.setWindowTitle(“水平布局管理”)
self.resize(800,200)

    hlayout = QHbobLayout()#按钮水平居左,垂直居上hlayout.addWidget(QPushButton(str(1)),0, Qt.AlignLeft|Qt.AlignTop)hlayout.addWidget(QPushButton(str(2)),0, Qt.AlignLeft|Qt.AlignTop)hlayout.addWidget(QPushButton(str(3),5))#这里5表示的是权重#水平居左,垂直居下hlayout.addWidget(QPushButton(str(4)),0,Qt.AlignLeft|Qt.AlignBottom)hlayout.addWidget(QpushButton(str(5)),0, Qt.ALignLeft|Qt.AlignBottom)self.setLayout(hlayout)

if name == “main”:
app = QApplication(sys.argv)
form = Winform()
form.show()
sys.exit(app.exec_())

一篇文章让你读懂PyQt5布局管理,绝对干货

https://cloud.tencent.com/developer/article/1437295

Qt Designer 设计PyQt5界面时自适应设置

https://blog.csdn.net/loovelj/article/details/79529625?depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-1&utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-1

Qt Creator 窗体控件自适应窗口大小布局

https://www.cnblogs.com/emouse/archive/2013/05/19/3087708.html


结合控件的SizePolicy属性,来控制布局管理中的控件的尺寸自适应方式。

控件的sizePolicy说明控件在布局管理中的缩放方式。Qt提供的控件都有一个合理的缺省sizePolicy,但是这个缺省值有时不能适合所有的布局,开发人员经常需要改变窗体上的某些控件的sizePolicy。一个QSizePolicy的所有变量对水平方向和垂直方向都适用。下面列举了一些最长用的值:

A. Fixed:控件不能放大或者缩小,控件的大小就是它的sizeHint。

B. Minimum:控件的sizeHint为控件的最小尺寸。控件不能小于这个sizeHint,但是可以

放大。

C. Maximum:控件的sizeHint为控件的最大尺寸,控件不能放大,但是可以缩小到它的最小

的允许尺寸。

D. Preferred:控件的sizeHint是它的sizeHint,但是可以放大或者缩小

E. Expandint:控件可以自行增大或者缩小

注:sizeHint(布局管理中的控件默认尺寸,如果控件不在布局管理中就为无效的值)

pyqt窗口控件跟随窗口大小变化而变化的方法

https://blog.csdn.net/zerfew/article/details/84107875?depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-3&utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-3
用designer时要注意,不要选中多个控件然后右键选择layout,要直接在mainwindow的widget,然后右键layout,一般选择网格布局,即可实现所有控件的排布,再根据需求,对控件大小进行特殊配置即可.

启用页面布局时,软件会自动排版,如果对排版不满意,可以对每个控件的长和宽的最小值和最大值进行配置,从而实现对页面布局的重新排版.比如不希望某个控件过大,就可以设置其最大长和宽为多少.如果希望不希望某个控件太小,就配置其最小的长和宽为多少.

pyqt5 布局 layout 收集相关推荐

  1. 10. PyQt5布局管理器

    PyQt5布局管理器 PyQt5布局管理器 1. QBoxLayout 及其子类 (盒式布局) 2. QGridLayout 类(网格布局) 3. QFormLayout 类(表单布局) PyQt5布 ...

  2. iOS SwiftUI篇-3 排版布局layout

    iOS SwiftUI篇-3 排版布局layout swiftUI提供的layout有: ZStack.GeometryReader.HStack.LazyVGrid.LazyHStack.LazyH ...

  3. .net托管环境下struct实例字段的内存布局(Layout)和大小(Size)

    在C/C++中,struct类型中的成员的一旦声明,则实例中成员在内存中的布局(Layout)顺序就定下来了,即与成员声明的顺序相同,并且在默认情况下总是按照结构中占用空间最大的成员进行对齐(Alig ...

  4. CSS 外补白(Margin) 内补白(Padding) 边框属性 定位(positioning)属性 布局(layout)属性

    CSS 布局(Layout) Properties 属性 CSS Version 版本 Inherit From Parent 继承性 Description 简介 display CSS1/CSS2 ...

  5. PyQt5——布局管理

    PyQt5布局管理使用方法详见:https://blog.csdn.net/jia666666/article/list/3?t=1& PyQt5布局管理汇总: 1.QHBoxLayout 2 ...

  6. 自定义View:测量measure,布局layout,绘制draw

    1. 什么是View 在Android的官方文档中是这样描述的:表示了用户界面的基本构建模块.一个View占用了屏幕上的一个矩形区域并且负责界面绘制和事件处理. 手机屏幕上所有看得见摸得着的都是Vie ...

  7. 系出名门Android(2) - 布局(Layout)和菜单(Menu)

    2019独角兽企业重金招聘Python工程师标准>>> 系出名门Android(2) - 布局(Layout)和菜单(Menu) 作者:webabcd 介绍 在 Android 中各 ...

  8. python gui控件案例_python GUI库图形界面开发之PyQt5布局控件QHBoxLayout详细使用方法与实例...

    PyQt5布局控件QHBoxLayout简介 采用QBOXLayout类可以在水平和垂直方向上排列控件,QHBoxLayout和QVBoxLayout类继承自QBoxLayout 采用QHBoxLay ...

  9. 界面布局layout

    界面布局Layout Android应用中讲究逻辑和视图分离,所以一般不建议在android程序中直接编写界面.通常的方式是在布局文件(res/layou/*.xml)中编写页面,然后在Activit ...

最新文章

  1. 阿里的STORM——JSTORM
  2. ASP.NET弹出一个对话框
  3. 蒸妙集团:大健康产业时代的弄潮儿,中国熏蒸行业的领跑者!
  4. DataTables中设置checkbox回显选中
  5. VTK:直线网格之RectilinearGridToTetr​​ahedra
  6. SAP CRM WebClient UI如何将后台存储的timestamp时间戳转换成本地时间
  7. 通用网站备案常见的备案场景及要求
  8. Manacher【p1210】回文检测
  9. 中国捆矛行业市场供需与战略研究报告
  10. python解密m3u8播放_Python3 通过m3u8连接获取完整媒体文件(附全网视频VIP观看方法)...
  11. echarts 迁徙图
  12. 古琴入门-古琴十大名曲-古琴教学——唐畅古琴
  13. 架构师日常-技术or业务
  14. android面试题整理(上)
  15. mysql热备工具_MySQL热备工具Xtrabackup
  16. java打印表格_如何在java中使用printf()打印出表格?
  17. ssm+JSP计算机毕业设计英雄联盟赛事新闻管理系统qeg6l【源码、程序、数据库、部署】
  18. win10任务栏固定图标删不掉
  19. PS(PhotoShop)替换纯色图片的颜色
  20. Delphi XE7 发布了

热门文章

  1. 283 款区块链游戏仅 5 款 DAU 破百,开发者涌入,“韭菜”已经开始逃
  2. 40%的中小企业已倒闭,谁来救助剩下的60%?
  3. 利安德巴塞尔公司最新分子回收中试车间正式投运
  4. 防火墙——网络攻击防范
  5. 深度优先搜索和广度优先搜索及典例分析(走迷宫问题(BFS)和棋盘问题(DFS))
  6. 滴滴外卖再扩张,这次美团真的是惹火烧身了
  7. sona:Spark on Angel大规模分布式机器学习平台介绍
  8. ole db提供程序 mysql_一、使用 Microsoft OLE DB Provider For ODBC 链接MySQL
  9. 【Python使用psycopg2三方库操作PostgreSQL的数据】
  10. Profile_Day05:企业级360全方位用户画像