当前位置:网站首页>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 .
边栏推荐
- Raspberry pie csi/usb camera uses mjpg to realize web camera monitoring
- Specify the format time, and fill in zero before the month and days
- Codeforces Round #800 (Div. 2)AC
- Problem - 1646C. Factorials and Powers of Two - Codeforces
- Opencv learning log 27 -- chip positioning
- Li Kou - 298th weekly match
- QT实现窗口置顶、置顶状态切换、多窗口置顶优先关系
- Determine the Photo Position
- F - birthday cake (Shandong race)
- 7-1 understand everything (20 points)
猜你喜欢
Penetration test (7) -- vulnerability scanning tool Nessus
“鬼鬼祟祟的”新小行星将在本周安全掠过地球:如何观看
807. Maintain the urban skyline
[exercise-5] (UVA 839) not so mobile (balance)
860. Lemonade change
力扣——第298场周赛
树莓派4B64位系统安装miniconda(折腾了几天终于解决)
1903. Maximum odd number in string
读取和保存zarr文件
QT实现窗口渐变消失QPropertyAnimation+进度条
随机推荐
Codeforces Round #801 (Div. 2)A~C
Codeforces Round #799 (Div. 4)A~H
Ball Dropping
[exercise-7] (UVA 10976) fractions again?! (fraction split)
The most complete programming language online API document
Truck History
Problem - 1646C. Factorials and Powers of Two - Codeforces
AcWing:第58场周赛
Radar equipment (greedy)
Calculate the time difference
Problem - 922D、Robot Vacuum Cleaner - Codeforces
Common configuration files of SSM framework
Write web games in C language
B - Code Party (girls' competition)
[exercise-1] (UVA 673) parentheses balance/ balanced brackets (stack)
Quick to typescript Guide
Codeforces - 1526C1&&C2 - Potions
Auto.js入门
It is forbidden to trigger onchange in antd upload beforeupload
QT实现窗口置顶、置顶状态切换、多窗口置顶优先关系