QAbstractButton
类是按钮小部件的抽象基类,提供按钮通用的功能。
按钮,常常被理解为触发一种动作请求或者命令,是与用户进行指令交互的操作。
Qt中Button系列根据用途被划分为不同的定义Qt Designer
提供6种Button
控件
QPushButton
按钮
QAbstractButton
类属性
-
text
显示文本 -
icon
设置图标 -
iconSize
图标大小 -
shortcut
设置快捷键 -
checkable
设置是否自动切换按钮 -
checked
设置默认选中状态 -
autoRepeat
设置是否会在用户按下时自动重复 -
autoExclusive
设置是否启用自动排他性(设置这个可以变成多选) -
autoRepeatDelay
自动重复的初始延迟(以毫秒为单位) -
autoRepeatInterval
自动重复的时间间隔(以毫秒为单位)
QPushButton
类属性
-
autoDefault
将按钮设置为对话框中的默认按钮 -
default
设置按钮的默认状态 -
flat
扁平化
QPushButton
信号
信号触发条件:
-
clicked()
当按钮被第一次按下然后释放时发出信号 -
clicked(bool)
当按钮被第一次按下然后释放时发出信号,并将当前状态传递给外界 -
pressed()
当鼠标光标在按钮内时按下鼠标左键发出信号 -
released()
当释放鼠标左键时发出信号 -
toggled(bool)
按钮的状态发生变化时发出信号,并将当前状态传递给外界
QToolButton
工具按钮
QAbstractButton
类属性
- 请参考
QPushButton
按钮
QToolButton
类属性
-
popupMode
弹出模式
DelayedPopup
延迟弹出MenuButtonPopup
菜单按钮弹出InstantPopup
即时弹出
-
toolButtonStyle
工具按钮样式
ToolButtonIconOnly
仅显示图标ToolButtonTextOnly
仅显示文本ToolButtonTextBesideIcon
文本出现在图标的旁边ToolButtonTextUnderIcon
文本出现在图标的下边ToolButtonFollowStyle
按照样式显示
-
autoRaise
设置按钮浮动 -
arrowType
箭头样式
NoArrow
没有箭头UpArrow
向上箭头DownArrow
向下箭头LeftArrow
向左箭头RightArrow
向右箭头
QToolButton
信号
信号触发条件:
- 前5个请参考
QPushButton
信号 -
triggered(QAction*)
当点击菜单中某个action
时触发,并将action
传递出来
QRadioButton
单选按钮
QAbstractButton
类属性
- 请参考
QPushButton
按钮
QRadioButton
信号
信号触发条件:
- 请参考
QPushButton
信号
QCheckBox
多选按钮
QAbstractButton
类属性
- 请参考
QPushButton
按钮
QCheckBox
类属性
-
tristate
三种显示状态,其中两种返回True
,一种返回False
信号触发条件:
- 前5个请参考
QPushButton
信号 -
stateChanged(int)
返回当前状态是数值,如果勾选了tristate
则返回(0,1,2)
QCommandLinkButton
命令链接按钮
QAbstractButton
类属性
- 请参考
QPushButton
按钮
QPushButton
类属性
-
autoDefault
将按钮设置为对话框中的默认按钮 -
default
设置按钮的默认状态
信号触发条件:
- 请参考
QPushButton
信号
QDialogButtonBox
按钮盒子
QDialogButtonBox
类属性
-
orientation
排列方式
Horizontal
水平排列Vertical
垂直排列
-
standardButtons
添加按钮 -
centerButtons
按钮居中
QDialogButtonBox
信号
信号触发条件:
-
accepted()
点击yes
,ok
等,表示真按钮时发出信号 -
clicked(QAbstractButton*)
点击所有按钮都可发出信号,并将所点击的按钮发送给外界 -
helpRequested()
点击help
按钮时发出信号 -
rejected()
点击no
,close
等,表示假按钮时发出信号