当前位置:网站首页>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 .
边栏推荐
- Penetration testing (5) -- a collection of practical skills of scanning King nmap and penetration testing tools
- Codeforces Round #802(Div. 2)A~D
- Codeforces Round #800 (Div. 2)AC
- Opencv learning log 26 -- detect circular holes and mark them
- Codeforces Round #799 (Div. 4)A~H
- Interval sum ----- discretization
- [exercise-6] (UVA 725) division = = violence
- Codeforces Round #801 (Div. 2)A~C
- [exercise-7] (UVA 10976) fractions again?! (fraction split)
- QT实现窗口置顶、置顶状态切换、多窗口置顶优先关系
猜你喜欢
第 300 场周赛 - 力扣(LeetCode)
Basic Q & A of introductory C language
QT模拟鼠标事件,实现点击双击移动拖拽等
去掉input聚焦时的边框
[exercise-5] (UVA 839) not so mobile (balance)
Suffix expression (greed + thinking)
Penetration test (8) -- official document of burp Suite Pro
Openwrt source code generation image
Flag framework configures loguru logstore
1529. Minimum number of suffix flips
随机推荐
Vs2019 initial use
Flask框架配置loguru日志庫
浏览器打印边距,默认/无边距,占满1页A4
Codeforces - 1526C1&&C2 - Potions
[exercise-6] (PTA) divide and conquer
1013. Divide the array into three parts equal to and
Analysis of protobuf format of real-time barrage and historical barrage at station B
AcWing:第56场周赛
Borg maze (bfs+ minimum spanning tree) (problem solving report)
Frida hook so layer, protobuf data analysis
栈的经典应用—括号匹配问题
Opencv learning log 24 -- Hough transform 2 (maximum interval and minimum length can be limited)
[exercise-4] (UVA 11988) broken keyboard = = (linked list)
生成随机密码/验证码
1323. Maximum number of 6 and 9
1689. Ten - the minimum number of binary numbers
frida hook so层、protobuf 数据解析
Sword finger offer II 019 Delete at most one character to get a palindrome
Truck History
Shell Scripting