当前位置:网站首页>QT QPushButton details
QT QPushButton details
2022-07-05 23:49:00 【Mr.codeee】
1.QPushButton summary
QAbstractButton Class is the base class of all button control classes , Contains many general button functions .
QPushButton Inherited from QAbstractButton, It can place text 、 Pictures, etc .
It is the most commonly used widget . Press ( Click on ) Button to command the computer to perform certain operations or answer questions . Typical buttons are “ determine ”、“ application ”、“ Cancel ”、“ close ”、“ yes ”、“ no ” and “ help ”.
2. Common methods
QPushButton Class provides 3 Constructors , Namely :
QPushButton(QWidget *parent = Q_NULLPTR)
QPushButton(const QString &text, QWidget *parent = Q_NULLPTR)
QPushButton(const QIcon &icon, const QString &text, QWidget *parent = Q_NULLPTR)parent Parameter is used to specify the parent window ;text Parameter is used to set the text to be displayed on the button ;icon Parameter is used to set the icon to be displayed on the button .
Other common methods :
| void setText(const QString &text) | Set the displayed text |
| void setIcon(const QIcon &icon) | Set icon |
| void setShortcut(const QKeySequence &key) | Set shortcut key |
| void setCheckable(bool) | Set whether you can select |
| void setChecked(bool) | Set whether it is selected or not |
| void setFont(const QFont &) | Set the font |
| void setEnabled(bool) | Set whether it can be pressed |
| void setAutoDefault(bool) | When the user presses Enter On enter , Whether to trigger the event of clicking the button . |
| void setAutoExclusive(bool) | This property saves whether auto exclusive is enabled |
Common signals :
There are mouse clicks 、 Press down 、 Lift signal .
void clicked(bool checked = false)
void pressed()
void released()
3. Example
3.1 Set text 、 picture .
QFont font;
font.setBold(true); // Set in bold
ui->pushButton->setFont(font);
QPixmap pixmap("test.png");
QIcon icon(pixmap);
ui->pushButton_2->setIcon(icon);Set the text and picture to appear together
You can see that there is only one highlight at any time .

ui->pushButton->setCheckable(true);
ui->pushButton_2->setCheckable(true);
ui->pushButton_3->setCheckable(true);
ui->pushButton_4->setCheckable(true);
ui->pushButton->setAutoExclusive(true);
ui->pushButton_2->setAutoExclusive(true);
ui->pushButton_3->setAutoExclusive(true);
ui->pushButton_4->setAutoExclusive(true);3.3 Button three state settings
Buttons have three states , mouse hover 、 Press down 、 Default .

QString a1 = "\
QPushButton#pushButton{\
border-image: url(:/1.png);\
}\
QPushButton#pushButton:hover{\
border-image: url(:/2.png);\
}"\
"QPushButton#pushButton:pressed{\
border-image: url(:/3.png);\
}";
ui->pushButton->setStyleSheet(a1);3.4 Other style sheet settings

Setting fillet , Frame , The font color , Attributes such as font size .
QString a2 = "QPushButton {\
border: 2px solid #8f8f91;\
border-radius: 6px;\
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,\
stop: 0 #f6f7fa, stop: 1 #dadbde);\
font-size: 24px;\
font-family: Microsoft YaHei;\
color: #ff0000;\
min-width: 80px;\
}";
ui->pushButton->setStyleSheet(a2);3.5QSS Style sheet reference
边栏推荐
- Biased sample variance, unbiased sample variance
- 698. Divided into k equal subsets ●●
- STM32__ 06 - single channel ADC
- C# Linq Demo
- Which side projects can be achieved? Is it difficult for we media to earn more than 10000 a month?
- 带外和带内的区别
- openssl-1.0.2k版本升级openssl-1.1.1p
- 【luogu CF487E】Tourists(圆方树)(树链剖分)(线段树)
- SpreadJS 15.1 CN 与 SpreadJS 15.1 EN
- White hat talks about web security after reading 2
猜你喜欢

Huawei simulator ENSP - hcip - MPLS experiment

Fiddler Everywhere 3.2.1 Crack

Zhongjun group launched electronic contracts to accelerate the digital development of real estate enterprises

Hcip course notes-16 VLAN, three-tier architecture, MPLS virtual private line configuration

MySQL replace primary key delete primary key add primary key

如何获取localStorage中存储的所有值

STM32__06—单通道ADC

GFS分布式文件系统

保研笔记四 软件工程与计算卷二(8-12章)

Redis高可用——主从复制、哨兵模式、集群
随机推荐
GFS分布式文件系統
Cwaitabletimer timer, used to create timer object access
Scala concurrent programming (II) akka
SpreadJS 15.1 CN 与 SpreadJS 15.1 EN
Différence entre hors bande et en bande
18.(arcgis api for js篇)arcgis api for js点采集(SketchViewModel)
用列表初始化你的vector&&initializer_list简介
STM32__06—单通道ADC
Do you regret becoming a programmer?
Neural structured learning - Part 3: training with synthesized graphs
The use of El cascader and the solution of error reporting
What if the C disk is not enough? Let's see how I can clean up 25g of temp disk space after I haven't redone the system for 4 years?
STM32__ 06 - single channel ADC
Technical specifications and model selection guidelines for TVs tubes and ESD tubes - recommended by jialichuang
【二叉搜索树】增删改查功能代码实现
4 points tell you the advantages of the combination of real-time chat and chat robots
21.PWM应用编程
How to improve eloquence
98. Verify the binary search tree ●●
Naoqi robot summary 26