当前位置:网站首页>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 .
边栏推荐
- Pytorch extract skeleton (differentiable)
- Ball Dropping
- [teacher Gao UML software modeling foundation] collection of exercises and answers for level 20 cloud class
- [exercise -11] 4 values why sum is 0 (and 4 values of 0)
- 1605. Sum the feasible matrix for a given row and column
- pytorch提取骨架(可微)
- 1689. Ten - the minimum number of binary numbers
- 875. 爱吃香蕉的珂珂 - 力扣(LeetCode)
- Data storage in memory & loading into memory to make the program run
- D - function (HDU - 6546) girls' competition
猜你喜欢

QT模拟鼠标事件,实现点击双击移动拖拽等

Codeforces Round #799 (Div. 4)A~H

Pytorch extract skeleton (differentiable)

Vs2019 initial use

C language is the watershed between low-level and high-level
![[exercise-5] (UVA 839) not so mobile (balance)](/img/8e/48dcf75f7347b36301df6fc129c09d.png)
[exercise-5] (UVA 839) not so mobile (balance)

Penetration test (4) -- detailed explanation of meterpreter command

Pyside6 signal, slot

1323. Maximum number of 6 and 9

Luogu P1102 A-B number pair (dichotomy, map, double pointer)
随机推荐
Codeforces Round #800 (Div. 2)AC
(POJ - 3579) median (two points)
Opencv learning log 24 -- Hough transform 2 (maximum interval and minimum length can be limited)
1323. Maximum number of 6 and 9
Ball Dropping
Programmers, what are your skills in code writing?
Interesting drink
Suffix expression (greed + thinking)
QT模拟鼠标事件,实现点击双击移动拖拽等
875. 爱吃香蕉的珂珂 - 力扣(LeetCode)
D - function (HDU - 6546) girls' competition
Penetration testing (5) -- a collection of practical skills of scanning King nmap and penetration testing tools
[exercise-1] (UVA 673) parentheses balance/ balanced brackets (stack)
日期加1天
Penetration test (7) -- vulnerability scanning tool Nessus
PySide6 信号、槽
Socket communication
Candy delivery (Mathematics)
Codeforces Round #799 (Div. 4)A~H
C language learning notes