当前位置:网站首页>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
边栏推荐
- GFS分布式文件系統
- 5. Logistic regression
- Which side projects can be achieved? Is it difficult for we media to earn more than 10000 a month?
- 15 MySQL stored procedures and functions
- Go language introduction detailed tutorial (I): go language in the era
- How to insert data into MySQL database- How can I insert data into a MySQL database?
- [Yu Yue education] NC machining technology reference materials of Shaanxi University of science and technology
- Qt QPushButton详解
- 【LeetCode】5. Valid Palindrome·有效回文
- CIS基准测试工具kube-bench使用
猜你喜欢
保研笔记二 软件工程与计算卷二(13-16章)
动态规划 之 打家劫舍
总结了 800多个 Kubectl 别名,再也不怕记不住命令了!
Dynamic planning: robbing families and houses
Live tiktok shop 2022 latest gameplay card slot overseas live e-commerce new traffic
GFS分布式文件系統
开关电源Buck电路CCM及DCM工作模式
Biased sample variance, unbiased sample variance
Do you regret becoming a programmer?
21.PWM应用编程
随机推荐
Make a short video clip number of we media film and television. Where can I download the material?
What is a humble but profitable sideline?
Open source CRM customer relationship system management system source code, free sharing
China Jinmao online electronic signature, accelerating the digitization of real estate business
Redis high availability - master-slave replication, sentinel mode, cluster
Introduction to JVM
Idea connects to MySQL, and it is convenient to paste the URL of the configuration file directly
C# Linq Demo
How to improve eloquence
保研笔记二 软件工程与计算卷二(13-16章)
Research notes I software engineering and calculation volume II (Chapter 1-7)
11gR2 Database Services for " Policy" and " Administrator" Managed databases (file I
15 MySQL stored procedures and functions
零犀科技携手集智俱乐部:“因果派”论坛成功举办,“因果革命”带来下一代可信AI
Common static methods of math class
2022.6.20-6.26 AI industry weekly (issue 103): new little life
Bao Yan notebook IV software engineering and calculation volume II (Chapter 8-12)
Neural structured learning - Part 3: training with synthesized graphs
ts类型声明declare
el-cascader的使用以及报错解决