当前位置:网站首页>QT implementation fillet window
QT implementation fillet window
2022-07-06 16:16:00 【Larry_ Yanan】
use QT When doing interface development , From time to time, there will be some more difficult style requirements , For example, you need a separate window , Set to fillet style .
//UI In file , Style settings for the outermost window
#ChooseUsbCamera{ // Class name
background-color: rgb(255, 255, 255); // The background color ( white )
border-radius: 10px; // The diameter of the corners
border-style:solid; // Border style ( Solid line )
border-width:2px; // Border width
border-color:rgb(213, 213, 213); // Border color
}
such , Simply make an interface effect with rounded corners and borders , Relatively beautiful .
But then the problem comes , Although it is set to fillet , But the transparency of the four top corners cannot be achieved , This will naturally add transparent code when the window is initialized :
setAttribute(Qt::WA_TranslucentBackground);
But it becomes the complete transparency of the window background , Even if you set the style related to the background
This may be due to the transparency setting , It overwrites our customized style . At this time, you need to reload paintEvent event , Redraw the picture
void ChooseUsbCamera::paintEvent(QPaintEvent *event)
{
QStyleOption opt;
opt.init(this);
QPainter painter(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this);
}
therefore , Finally, this simple but troublesome rounded window effect is achieved :
You can see , Its four corners are transparent , Achieve the effect of rounded corners . And there is a little gray border effect , It's not obvious hh.
In fact, if you are a part in the window , Set the style in the same way , Or fill the image with transparency directly , It doesn't need to be so troublesome . But the top-level window is often not set up , After studying for a long time, I took many detours hh, So I made a special note .
边栏推荐
- TCP's three handshakes and four waves
- 顺丰科技智慧物流校园技术挑战赛(无t4)
- Suffix expression (greed + thinking)
- Generate random password / verification code
- Opencv learning log 29 -- gamma correction
- PySide6 信号、槽
- Find 3-friendly Integers
- [exercise -11] 4 values why sum is 0 (and 4 values of 0)
- 1013. Divide the array into three parts equal to and
- Advancedinstaller安装包自定义操作打开文件
猜你喜欢
[exercise-4] (UVA 11988) broken keyboard = = (linked list)
分享一个在树莓派运行dash应用的实例。
antd upload beforeUpload中禁止触发onchange
树莓派4B64位系统安装miniconda(折腾了几天终于解决)
807. Maintain the urban skyline
Pytorch extract skeleton (differentiable)
Flask框架配置loguru日志库
Some problems encountered in installing pytorch in windows11 CONDA
Frida hook so layer, protobuf data analysis
C language must memorize code Encyclopedia
随机推荐
Codeforces Round #801 (Div. 2)A~C
Acwing - game 55 of the week
875. Leetcode, a banana lover
QT实现窗口置顶、置顶状态切换、多窗口置顶优先关系
Openwrt source code generation image
力扣:第81场双周赛
树莓派4B64位系统安装miniconda(折腾了几天终于解决)
Understand what is a programming language in a popular way
Bidirectional linked list - all operations
TCP's three handshakes and four waves
D - function (HDU - 6546) girls' competition
Vs2019 initial use
AcWing——第55场周赛
Programmers, what are your skills in code writing?
C language must memorize code Encyclopedia
QNetworkAccessManager实现ftp功能总结
树莓派CSI/USB摄像头使用mjpg实现网页摄像头监控
window11 conda安装pytorch过程中遇到的一些问题
Flask框架配置loguru日志库
Nodejs crawler