当前位置:网站首页>Qt程序美化之样式表的使用方法,Qt使用图片作为背景与控件透明化,Qt自定义按钮样式
Qt程序美化之样式表的使用方法,Qt使用图片作为背景与控件透明化,Qt自定义按钮样式
2022-07-26 01:50:00 【百口可乐__】
如何让你的qt程序更加美观?
样式表的使用方法:对于控件右键,改变样式表
你可以为该控件编辑自己的样式表
为窗口添加背景图片:/bg2.jpeg
#MainWindow{
background-image: url(:/bg2.jpeg);
}
//MainWindow是该控件的对象名称
不能写成下面这种,否则窗口内所有控件背景都被改变
background-image: url(:/bg2.jpeg);

为按钮设置透明、字体和颜色
#pushButton{
background:transparent;//背景透明
//background-color:rgba(255, 255, 255, 0);//这样也可以设置透明背景,并且设置透明度
color: rgb(85, 15, 108);
font: 22pt "Agency FB";
}

如何改变鼠标悬停到按钮上与点击时的样式?
#pushButton{
background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(0, 222, 0, 255), stop:1 rgba(255, 255, 111, 255));
color: rgb(85, 15, 18);
font: 22pt "Agency FB";
}
//hover是鼠标悬停时的样式
#pushButton:hover{
color: rgb(85, 15, 108);
background-color: rgb(25, 14, 249);
font: 22pt "Agency FB";
}
//pressed是鼠标点击时的样式
#pushButton:pressed{
color: rgb(185, 115, 108);
background-color: rgb(55, 124, 249);
font: 22pt "Agency FB";
}

另外,可以在代码中动态设置样式表:调用控件的setStyleSheet方法
改变tableWidget表头样式:
ui->tableWidget->horizontalHeader()->setStyleSheet("QHeaderView::section{"
"background-color:rgb(0, 0, 255);"
"font:15pt '新宋体';"
"color: black;"
"}");
更多的参考qt帮助手册
边栏推荐
- 图像批处理高斯滤波降噪+峰值信噪比计算
- SQL injection tutorial: learn through examples
- [unity] random generation of two-dimensional cave map
- My Mysql to MySQL data table synchronization, only the code written in the first order will take effect, and the rest will not take effect. This may be
- Dataframe modifies the value of a row or column position
- 6 + 1 skills of Software Test Engineer
- “蔚来杯“2022牛客暑期多校训练营2 I.[let fat tension] 矩阵乘法 J.[Link with Arithmetic Progression]线性回归
- FFT用于估计插值后的图像重采样因子
- Go operation excel library excel use
- Zhinai buys melons (DP backpack)
猜你喜欢

Integer data type in C language (do you really understand it)

Typora expiration solution, what if typora can't open

AutoCAD -- Method of calculating area

The e-commerce project is written in the resume. How to answer it during the interview

The best way to practice Animation: cover transition

AUTOCAD——计算面积的方法

P3166 number triangle (tolerance and exclusion +gcd)

Overview of database stress testing methods

图像批处理高斯滤波降噪+峰值信噪比计算
![4QAM, 16QAM modulation and demodulation simulation circuit, observe and analyze QAM constellation and bit error rate curve [matlab code]](/img/95/5b9a2347d20cc5da0d2920b7f583ce.png)
4QAM, 16QAM modulation and demodulation simulation circuit, observe and analyze QAM constellation and bit error rate curve [matlab code]
随机推荐
Dataframe modifies the value of a row or column position
登堂入室soc之arm汇编基础
"Weilai Cup" 2022 Niuke summer multi school training camp 2 i.[let fat tension] matrix multiplication j.[link with arithmetic progression] linear regression
D. Permutation restoration (greedy + double pointer)
6 + 1 skills of Software Test Engineer
4QAM、16QAM 调制与解调仿真电路,观察并分析QAM星座图和误码率曲线【matlab代码】
There is no setter method in grpc list under flutter. How to use related attributes
推荐系统-协同过滤在Spark中的实现
Summary after reading "poor dad and rich dad"
SQL injection tutorial: learn through examples
8. Learn Mysql to create data tables
旅行 (拆点分层)
Is it safe to buy funds in stock accounts? Professional answers
Shell exercises
In spark SQL, date is used to display the day of the week according to the year, month and day_ format(date,‘u‘)
01. MySQL transaction isolation level and concurrent database access
保护系统日志服务器和设备
Qtreewidget dotted line setting
"Weilai Cup" 2022 Niuke summer multi school training camp 2 h.[take the elevator] maintenance section
[in simple terms, play with FPGA learning 11 --- testbench writing skills 2]