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

推荐订阅源

WordPress大学
WordPress大学
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 三生石上(FineUI控件)
雷峰网
雷峰网
爱范儿
爱范儿
P
Proofpoint News Feed
Security Archives - TechRepublic
Security Archives - TechRepublic
Latest news
Latest news
The Hacker News
The Hacker News
Cyberwarzone
Cyberwarzone
博客园 - 【当耐特】
Project Zero
Project Zero
小众软件
小众软件
T
Tailwind CSS Blog
量子位
博客园 - 聂微东
I
Intezer
美团技术团队
S
SegmentFault 最新的问题
T
Tor Project blog
Spread Privacy
Spread Privacy
V
Vulnerabilities – Threatpost
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Jina AI
Jina AI
罗磊的独立博客
B
Blog RSS Feed
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
T
Troy Hunt's Blog
有赞技术团队
有赞技术团队
Google DeepMind News
Google DeepMind News
宝玉的分享
宝玉的分享
C
Cisco Blogs
L
LINUX DO - 热门话题
Last Week in AI
Last Week in AI
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
AI
AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Microsoft Azure Blog
Microsoft Azure Blog
L
LINUX DO - 最新话题
Know Your Adversary
Know Your Adversary
GbyAI
GbyAI
Engineering at Meta
Engineering at Meta
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Recent Commits to openclaw:main
Recent Commits to openclaw:main
L
Lohrmann on Cybersecurity
The Register - Security
The Register - Security
L
LangChain Blog
博客园 - 叶小钗
T
Tenable Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC

埃氮幂の命名空间

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