QT按键组件

目录

1、按键组件

2、QPushButton

2.1、构造函数

2.2、常用函数

2.3、Signals

3、QToolButton

3.1、构造函数

3.2、常用函数 

3.3、Signals

4、QRadioButton

4.1、构造函数

4.2、常用函数

5、QCheckBox

5.1、构造函数

5.2、常用函数

5.3、Signals

6、QCommandLinkButton

6.1、构造函数

6.2、Signals

7、QDialogButtonBox

7.1、构造函数

7.2、常用函数

7.3、Signals


1、按键组件

QPushButton下压按钮。继承 QAbstractButton 类。通常用于执行命令或触发事件。
QToolButton工具按钮。继承 QAbstractButton 类。QToolButton通常显示的是图标,而不是文本标签(通常使用在ToolBar 中)。 
QRadioButton选择按钮。继承 QAbstractButton 类。 RadioButton通常成组出现,用于提供多个互斥选项。
QCheckBox检查框。继承 QAbstractButton。QCheckBox与 RadioButton 的区别是选择模式:RadioButton 提供多选一,QCheckBox提供多选多。
QCommandLinkButton
 
命令链接按钮。继承 QPushButton。 CommandLinkButton 除带有正常的按钮上的文字描述文本外,默认情况下,它也将携带一个箭头图标,表明按下按钮将打开另一个窗口或页面。
QDialogButtonBox
 
对话框按钮。继承 QWidget。常用于对话框里自定义按钮,比如“确定”和“取消” 按钮。

2、QPushButton

2.1、构造函数

QPushButton(QWidget *parent = nullptr);
QPushButton(const QString &text, QWidget *parent = nullptr);
QPushButton(const QIcon& icon, const QString &text, QWidget *parent = nullptr);

参数 parent:一般设置为this。

参数 text:设置QPushButton名称

参数 icon:设置QPushButton图标

2.2、常用函数

setGeometry(int x, int y, int width, int height)设定QPushButton对象位置
setMinimumWidth(int minw); 设置最小宽度
setMinimumHeight(int minh)设置最小高度
setMaximumWidth(int maxw)设置最大宽度
setMaximumHeight(int maxh)设置最大高度
setFixedSize(int w, int h)设置固定大小
setText(const QString &text)设定文本
isEnabled()是否使能
setEnabled(bool)设置使能
void setToolTip(const QString &)
QString toolTip()

2.3、常用信号

void clicked(void)

3、QToolButton

可以将 toolButton(工具按钮)添加到 toolBar(工具条/工具栏)上。

3.1、构造函数

QToolButton(QWidget * parent=0);

参数 parent:一般设置为this。

3.2、常用函数 

setGeometry(int x, int y, int width, int height)设定QToolButton对象位置
setText(const QString &text)设定QToolButton文本
setIcon(const QIcon & icon)设置QToolButton图标
setToolButtonStyle(Qt::ToolButtonStyle style)设置QToolButton的样式,如设置为文本置于图标下方
setFixedSize(int w, int h)设置固定大小
isEnabled()是否使能
setEnabled(bool)设置使能
void setDefaultAction(QAction *)与一个Action关联,按钮的文字、图标、ToolTip都将自动设置为与关联的Action一致,单击就是执行Action槽函数
void setPopupMode(ToolButtonPopupMode mode)设置其弹出菜单的模式。
void setToolButtonStyle(Qt::ToolButtonStyle style)设置按钮样式
void setMenu(QMenu* menu)为按钮设置下拉菜单对象

工具栏上具有下拉菜单的按钮需要动态创建。

QToolButton::MenuButtonPopup按钮右侧有一个向下的小箭头,必须单击这个小按钮才会弹出下拉菜单,单击按钮不会弹出下拉菜单
QToolButton::InstantPopup工具按钮的右下角显示一个小的箭头,单击按钮直接弹出下拉菜单,即使为这个按钮设置了关联的Action,也不会执行Action的功能

3.3、常用信号

void clicked(void)

4、QRadioButton

单选框通常呈现给用户一个“多选一”的选择。在一组单选框中,一次只能选中一个单选框。默认在同一个父对象下,初始化后点击它们是互斥状态。

4.1、构造函数

explicit QRadioButton(QWidget *parent=0);
explicit QRadioButton(const QString &text, QWidget *parent=0);

参数 parent:一般设置为this。

参数 text:设置QRadioButton名称

4.2、常用函数

setGeometry(int x, int y, int width, int height)设定QRadioButton对象位置
setText(const QString &text)设定QRadioButton文本
setChecked(bool checked)设置QRadioButton按键状态
setCheckable(bool checkable)设置QRadioButton是否可以check

5、QCheckBox

5.1、构造函数

explicit QCheckBox(QWidget *parent=0);
explicit QCheckBox(const QString &text, QWidget *parent=0);

参数 parent:一般设置为this。

参数 text:设置QCheckBox名称。

5.2、常用函数

setGeometry(int x, int y, int width, int height)设定QCheckBox对象位置
setText(const QString &text)设定QCheckBox文本
setChecked(bool)设置QCheckBox按键状态
setCheckable(bool)设置QCheckBox是否可以check
isChecked()是否check

三态模式

setTristate(bool tristate)设置三态模式
setCheckState(Qt::CheckState state)设置三态模式复选框状态

5.3、常用信号

void stateChanged(int state)

6、QCommandLinkButton

CommandLinkButton 除带有正常的按钮上的文字描述文本外,默认情况下,它也将携带一个箭头图标,表明按下按钮将打开另一个窗口或页面。

6.1、构造函数

explicit QCommandLinkButton(QWidget *parent=0);
explicit QCommandLinkButton(const QString &text, QWidget *parent=0);
explicit QCommandLinkButton(const QString &text, const QString &description, QWidget *parent=0);

参数 parent:一般设置为this。

参数 text:设置QCommandLinkButton名称。

参数 description:设置QCommandLinkButton的描述。

6.2、常用信号

void clicked(void)

注:一般在solt中使用QDesktopServices类打开系统文件夹对话框。

QDesktopServices::openUrl(QUrl("file:home/") );

7、QDialogButtonBox

QDialogButtonBox 允许开发人员向其添加按钮,并将自动使用适合用户桌面环境的布局(可以使用系统的自带的对话框按钮,也可以自己定义对话框按钮)。

7.1、构造函数

QDialogButtonBox(QWidget *parent = 0);
QDialogButtonBox(Qt::Orientation orientation, QWidget *parent = 0);
QDialogButtonBox(StandardButtons buttons, QWidget *parent = 0);
QDialogButtonBox(StandardButtons buttons, Qt::Orientation orientation,
                     QWidget *parent = 0);

参数 parent:一般设置为this。

参数 orientation:对齐方式

Qt::Vertical垂直
Qt::Horizontal水平

参数 buttons:初始化时添加标准按钮

QDialogButtonBox::Ok
QDialogButtonBox::Save
QDialogButtonBox::SaveAll            
QDialogButtonBox::Open               
QDialogButtonBox::Yes                
QDialogButtonBox::YesToAll           
QDialogButtonBox::No                 
QDialogButtonBox::NoToAll            
QDialogButtonBox::Abort              
QDialogButtonBox::Retry              
QDialogButtonBox::Ignore             
QDialogButtonBox::Close              
QDialogButtonBox::Cancel             
QDialogButtonBox::Discard            
QDialogButtonBox::Help               
QDialogButtonBox::Apply              
QDialogButtonBox::Reset              
QDialogButtonBox::RestoreDefaults    

7.2、常用函数

setGeometry(int x, int y, int width, int height)设定QCheckBox对象位置
addButton(QAbstractButton *button, ButtonRole role)添加按钮

7.3、Signals

void clicked(QAbstractButton * )

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值