当前位置:网站首页>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
边栏推荐
- Zero rhino technology joined hands with the intelligence Club: the "causal faction" forum was successfully held, and the "causal revolution" brought the next generation of trusted AI
- How to design API return code (error code)?
- 11gR2 Database Services for " Policy" and " Administrator" Managed databases (file I
- 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?
- orgchart. JS organization chart, presenting structural data in an elegant way
- Huawei simulator ENSP - hcip - MPLS experiment
- PV静态创建和动态创建
- JVM details
- SpreadJS 15.1 CN 与 SpreadJS 15.1 EN
- C# Linq Demo
猜你喜欢
CIS基准测试工具kube-bench使用
Neural structured learning - Part 3: training with synthesized graphs
Spire Office 7.5.4 for NET
My colleagues quietly told me that flying Book notification can still play like this
18.(arcgis api for js篇)arcgis api for js点采集(SketchViewModel)
GFS分布式文件系统
"14th five year plan": emphasis on the promotion of electronic contracts, electronic signatures and other applications
Spire. PDF for NET 8.7.2
Scala concurrent programming (II) akka
Spécifications techniques et lignes directrices pour la sélection des tubes TVS et ESD - Recommandation de jialichuang
随机推荐
C# 反射与Type
Part III Verilog enterprise real topic of "Niuke brush Verilog"
My colleagues quietly told me that flying Book notification can still play like this
98. Verify the binary search tree ●●
Senparc.Weixin.Sample.MP源码剖析
【GYM 102832H】【模板】Combination Lock(二分图博弈)
STM32__06—单通道ADC
保研笔记四 软件工程与计算卷二(8-12章)
保研笔记一 软件工程与计算卷二(1-7章)
Technical specifications and model selection guidelines for TVs tubes and ESD tubes - recommended by jialichuang
STM32__ 06 - single channel ADC
Russian Foreign Ministry: Japan and South Korea's participation in the NATO summit affects security and stability in Asia
GFS distributed file system
动态规划 之 打家劫舍
Spire Office 7.5.4 for NET
Redis高可用——主从复制、哨兵模式、集群
【SQL】各主流数据库sql拓展语言(T-SQL 、 PL/SQL、PL/PGSQL)
如何让同步/刷新的图标(el-icon-refresh)旋转起来
妙才周刊 - 8
Common static methods of math class