惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
人人都是产品经理
人人都是产品经理
Cisco Talos Blog
Cisco Talos Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
V
V2EX
博客园 - 三生石上(FineUI控件)
Martin Fowler
Martin Fowler
WordPress大学
WordPress大学
D
Docker
S
SegmentFault 最新的问题
博客园 - 聂微东
美团技术团队
Apple Machine Learning Research
Apple Machine Learning Research
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Last Week in AI
Last Week in AI
M
MIT News - Artificial intelligence
F
Fortinet All Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The GitHub Blog
The GitHub Blog
GbyAI
GbyAI
L
LangChain Blog
Vercel News
Vercel News
博客园 - 叶小钗
MongoDB | Blog
MongoDB | Blog
Stack Overflow Blog
Stack Overflow Blog
H
Help Net Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Cloudflare Blog
Engineering at Meta
Engineering at Meta
T
Threat Research - Cisco Blogs
T
Threatpost
Scott Helme
Scott Helme
T
Tailwind CSS Blog
Latest news
Latest news
Stack Overflow Blog
Stack Overflow Blog
Blog — PlanetScale
Blog — PlanetScale
The Register - Security
The Register - Security
罗磊的独立博客
P
Proofpoint News Feed
腾讯CDC
S
Schneier on Security
雷峰网
雷峰网
A
About on SuperTechFans
T
Tenable Blog
F
Full Disclosure
Cyberwarzone
Cyberwarzone
博客园_首页
有赞技术团队
有赞技术团队
K
Kaspersky official blog

文章列表

埃氮幂の命名空间 埃氮幂の命名空间 P13020 [GESP202506 八级] 遍历计数 题解 Moonlark(Nonebot2+Python)命令式聊天机器人插件开发记录 埃氮幂の命名空间 P3435 [POI 2006] OKR-Periods of Words 题解 埃氮幂の命名空间 埃氮幂の命名空间 埃氮幂の命名空间 埃氮幂の命名空间 埃氮幂の命名空间 埃氮幂の命名空间 埃氮幂の命名空间 埃氮幂の命名空间 Hexo博客0氪建站记录(下) 埃氮幂の命名空间 埃氮幂の命名空间
埃氮幂の命名空间
2025-01-18 · via

最近在研究Qt的过程中,又积攒了一些问题,下面是解决方案。

1.QColor.lighter()QColor.darker()

在Qml中,使用Qt.lighter()Qt.darker()来让颜色变得更亮或更暗。括号里填的是相比原来颜色亮了或暗了多少倍,值在1左右。 但是,如果这样使用到QtWidgets中,lighter的效果会很暗,darker的效果会很亮,反而达到了相反的效果。

这是因为,在Python程序文件中,括号内的值要乘以100,QColor是按原来的百分之多少来把颜色变亮或变暗的。

2.Qt同时继承两个类,窗口闪退

有一次,我继承QFrame自己定义了一个Frame类,这个类带有自动显示、鼠标事件检测等功能。 但是,QFrame是没有显示文字的功能的,所以我就尝试,制作一个Label类,同时继承(即载括号里写两个父类)可不可以呢?

PYTHON
class Label(Frame,QLabel):
    def __init__(self,parent=None,show=True,autoAdjust=True):
        global widgetCount
        super().__init__(parent)

当然,窗口刚显示就直接消失了,这个可能就是Qt的一个问题,所以建议以后不要同时继承两个Qt类(Frame是继承QFrame的,所以也算)。

3.QWidget.mouseMoveEvent()点击鼠标再移动才触发事件

这也是Qt的一个bug。 解决这个问题的方法很简单,在自己定义的类的构造函数(__init__())中加入这么一行: ```python

class YourWidget(QWidget):

TEXT
# def __init__(self):
    # 其他内容
    self.setMouseTracking(True)
TEXT

这样,鼠标直接在窗口中移动,`mouseMoveEvent()`也能触发了。

# 4.如何设置窗口即无边框又圆角

制作组件的时候,常常需要自定义一些样式。比如我需要无边框圆角窗口。
于是就有了这样的代码:

python from PySide6.QtWidgets import * from PySide6.QtCore import * app=QApplication() class MyWindow(QWidget): def __init__(self): super().__init__() self.setWindowFlags(Qt.WindowType.FramelessWindowHint) self.setStyleSheet('border-radius: 4') window=MyWindow() window.show() app.exec()

TEXT

但是,效果并不好,没有圆角:

![image](https://s1.imagehub.cc/images/2025/01/18/0a44771ae8c21cc9aebca90f95f14e48.png)

这是因为Windows窗口不能设置圆角。但是可以把窗口透明,然后自己做一个背景控件再设置背景控件的圆角。因为背景是控件,所以是可以设置圆角样式的。

最终代码:

python from PySide6.QtWidgets import * from PySide6.QtCore import * app=QApplication() class MyWindow(QWidget): def __init__(self): super().__init__() self.setWindowFlags(Qt.WindowType.FramelessWindowHint) self.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground) self.setStyleSheet('background-color:transparent') self.background1=QWidget(self) self.background1.resize(self.size()) self.background1.setStyleSheet('background-color:#FFFFFF;border-radius: 10') window=MyWindow() window.show() app.exec()

```

效果: image

Qt Troubleshoot(二)

作者

Admibrill

发布于

2025-01-18

更新于

2025-01-18

许可协议