当前位置:网站首页>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
边栏推荐
猜你喜欢

Spreadjs 15.1 CN and spreadjs 15.1 en

Brushless drive design -- on MOS drive circuit

Part III Verilog enterprise real topic of "Niuke brush Verilog"

【LeetCode】5. Valid Palindrome·有效回文

Redis高可用——主从复制、哨兵模式、集群

openssl-1.0.2k版本升级openssl-1.1.1p

Live tiktok shop 2022 latest gameplay card slot overseas live e-commerce new traffic

Rasa 3.x 学习系列-Rasa X 社区版(免费版) 更改

Neural structured learning - Part 2: training with natural graphs

STM32__ 06 - single channel ADC
随机推荐
[Yu Yue education] NC machining technology reference materials of Shaanxi University of science and technology
JVM details
TVS管和ESD管的技術指標和選型指南-嘉立創推薦
Biased sample variance, unbiased sample variance
Hcip course notes-16 VLAN, three-tier architecture, MPLS virtual private line configuration
Spire.PDF for NET 8.7.2
UVA11294-Wedding(2-SAT)
激光slam学习记录
The use of El cascader and the solution of error reporting
成为程序员的你,后悔了吗?
【EF Core】EF Core与C# 数据类型映射关系
Rasa 3. X learning series -rasa 3.2.1 new release
5. Logistic regression
俄外交部:日韩参加北约峰会影响亚洲安全稳定
98. 验证二叉搜索树 ●●
Senparc.Weixin.Sample.MP源码剖析
【luogu P3295】萌萌哒(并查集)(倍增)
Asynchronous task Whenall timeout - Async task WhenAll with timeout
Problem solving win10 quickly open ipynb file
如何让同步/刷新的图标(el-icon-refresh)旋转起来