6

PyQt5入门(七)常用控件

 3 years ago
source link: https://blog.csdn.net/weixin_44593822/article/details/112628612
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

目录

按钮控件(QpushButton)

单选按钮控件QRatioButton

复选框控件QCheckBox

下拉列表控件ComboBox

滑块控件QSlider

滑块步长和间隔的区别

计数器控件QSpinBox


按钮控件(QpushButton)

QAbstractButton(所有按钮控件的父类)

QPushButton(普通按钮)
AToolButton(工具条按钮)
QRadioButton(单选框按钮)
QCheckBox(复选框按钮)

运行结果:

开始啥都不要选,先按一个一个回车,果然按钮4反应了,然后连按两下按钮1,再用热键Alt+m,再点按钮2,按钮3点不了。

单选按钮控件QRatioButton

在一个容器内的单选按钮是互斥的,即选中了一个单选按钮,就不能再选中另一个单选按钮,也就是不能同时处于选中状态。在不同容器中的单选按钮是分开的,互不影响。

运行结果:

    (控制台)

复选框控件QCheckBox

3种状态:

未选中:0

半选中:1

tristate属性表示复选框是三种状态还是两种状态,如果tristate为true,则表示复选框中有选中,半选中,未选中三种状态,即setTristate(True)即表示允许半选中。

self.checkbox3.setCheckState(Qt.PartiallyChecked)可设置的三种状态

运行结果:

    可见半选框这种状态时处于半选中状态

  此时半选框处于选中状态

下拉列表控件ComboBox

运行结果:

滑块控件QSlider

bug:

TypeError: __init__() takes 1 positional argument but 2 were given

我把类名直接命名成QSlider了。。。关于函数类这一块的基础知识有点忘了

代码:

运行结果:

俩个都行,自己试试吧,没啥好说的

滑块步长和间隔的区别

间隔就是刻度点的间隔,比如slider1刻度范围是12-48,刻度间隔是6,所以有(48-12)/6=6个间隔,即7个刻度点

而对于步长,你先用鼠标选中上图中的任一个滑动条,然后用上下(或左右)键调节,每次调节的大小就是步长。

以slider1为例,易知步长是3。

计数器控件QSpinBox

运行结果:


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK