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

推荐订阅源

K
Kaspersky official blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
Cyberwarzone
Cyberwarzone
S
Securelist
S
Schneier on Security
V
Vulnerabilities – Threatpost
Latest news
Latest news
G
GRAHAM CLULEY
C
CERT Recently Published Vulnerability Notes
T
The Exploit Database - CXSecurity.com
Scott Helme
Scott Helme
Know Your Adversary
Know Your Adversary
雷峰网
雷峰网
S
SegmentFault 最新的问题
Jina AI
Jina AI
A
About on SuperTechFans
GbyAI
GbyAI
F
Full Disclosure
T
Tenable Blog
博客园 - 聂微东
P
Privacy International News Feed
Recorded Future
Recorded Future
PCI Perspectives
PCI Perspectives
MongoDB | Blog
MongoDB | Blog
L
LINUX DO - 热门话题
NISL@THU
NISL@THU
Microsoft Security Blog
Microsoft Security Blog
C
Check Point Blog
The GitHub Blog
The GitHub Blog
IT之家
IT之家
S
Secure Thoughts
Cloudbric
Cloudbric
S
Security @ Cisco Blogs
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
博客园_首页
N
News | PayPal Newsroom
有赞技术团队
有赞技术团队
I
Intezer
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
大猫的无限游戏
大猫的无限游戏
The Register - Security
The Register - Security
WordPress大学
WordPress大学
Hugging Face - Blog
Hugging Face - Blog
Martin Fowler
Martin Fowler
小众软件
小众软件
人人都是产品经理
人人都是产品经理
C
Cyber Attacks, Cyber Crime and Cyber Security
宝玉的分享
宝玉的分享
Schneier on Security
Schneier on Security

埃氮幂の命名空间

埃氮幂の命名空间 埃氮幂の命名空间 埃氮幂の命名空间 埃氮幂の命名空间 埃氮幂の命名空间 埃氮幂の命名空间 埃氮幂の命名空间 埃氮幂の命名空间 埃氮幂の命名空间 埃氮幂の命名空间 埃氮幂の命名空间 埃氮幂の命名空间 埃氮幂の命名空间 埃氮幂の命名空间 埃氮幂の命名空间 埃氮幂の命名空间 埃氮幂の命名空间
埃氮幂の命名空间
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