标签: pyqt6

mach-o 文件,但不兼容的架构有“x86_64”,需要“arm64e”M1 MAC

from PyQt6.QtWidgets import *

from model.Department import Department
from view.main_window import Ui_Form
from model.Department import Department, Employee

class Homewidget(QWidget,Ui_Form):

    def __init__(self):
        QWidget.__init___(self)
        self.setupUi(self)

        self.depts = Department.get_all_depts()
        self.load_depts

        self.emps= Employee.get_all_emps()
        self.load_emps

        self.cb_depts.currentIndexChanged.connect(self.filter_emps_by_dept)
        self.le_search.textChanged.connect(self.filter_emps_by_name)


    def load_depts(self):
        names = [d.dept_name for d in self.depts]
        self.cb_depts.addItems(names)
    def load_emps(self):
        self.tb_emps.setRowCount(0)
        for i, e in self.emps:
            self.tb_emps.insertRow(i)
            for j, info in enumerate(e.__dict__.values()):
                self.tb_emps.setItem(i , j, QTableWidgetItem(str(info)))

    def filter_emps_by_dept(self, idx):
                    self.load_emps()
                    if idx != 0:
                        dept = self.depts[idx - 1]
                        for i, e in enumerate(self.emps):
                            if e.dept_id …
Run Code Online (Sandbox Code Playgroud)

python mach-o arm64 apple-m1 pyqt6

19
推荐指数
1
解决办法
2万
查看次数

用Qt在屏幕上绘制透明图像

我正在尝试在整个屏幕上绘制具有透明背景的图像。我对 Xlib 做了类似的事情,但我想我应该尝试 Qt,这样我的程序就可以在 X11 之外的不同环境中运行。在做出承诺之前,老实说,我只是在互联网上搜索试图找到一个可行的示例,但失败了。

所以我有一个想要覆盖在屏幕上的坐标图像。该图像是具有透明背景的PNG。这是我想要看到的图片,带有坐标的桌面: 在此输入图像描述

这是我的 PyQt6 代码,它全屏绘制图像,但遗憾的是你看不到它,它有黑色背景:

import sys
from PyQt6.QtCore import Qt
from PyQt6.QtGui import QImage
from PyQt6.QtWidgets import QApplication, QMainWindow

from PyQt6.QtGui import QPainter

class Img(QMainWindow):
    def __init__(self, img_path, parent=None):
        super().__init__(parent)
        self.qimg = QImage(img_path)
        self.setStyleSheet('QMainWindow {background:transparent}')
        self.setWindowFlags(
            Qt.WindowType.WindowStaysOnTopHint |
            Qt.WindowType.FramelessWindowHint |
            Qt.WindowType.WindowTransparentForInput
        )
        self.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground)

    def paintEvent(self, qpaint_event):
        painter = QPainter(self)
        rect = qpaint_event.rect()
        painter.drawImage(rect, self.qimg)
        self.showFullScreen()


if __name__ == "__main__":
    app = QApplication(sys.argv)
    img_path = 'coords.png'
    window = Img(img_path)
    window.show()
    sys.exit(app.exec())
Run Code Online (Sandbox Code Playgroud)

答案不需要是 PyQt6,也许是 PyQt5 或用 …

qt pyqt pyqt5 pyqt6

9
推荐指数
1
解决办法
1461
查看次数

PyQt6 的 Qt 模块替代方案

我只是将我的应用程序从 PyQt5 迁移到 PyQt6。据我了解,Qt 模块已在 Qt6 中删除。我有“Qt.AlignCenter”、“Qt.ToolButtonTextUnderIcon”、“Qt.LeftToolBarArea”等不再工作的东西。Qt6 中有此功能的替代方案吗?

python enums pyqt pyqt6

8
推荐指数
1
解决办法
9204
查看次数

PyQt6 中缺少 QEvent.MouseButtonPress 枚举类型?

在 PyQt5 中,我们可以使用 QEvent 类验证事件发生,例如 QEvent.MouseButtonPress。在 PyQt6 中,该声明不再有效。PyQt6.QtCore.QEvent我已经检查了和类的成员PyQt6.QtGui.QMouseEvent,我似乎无法找到包含 MouseButtonPress 事件值的正确 Enum 类。

PyQt5 示例我正在尝试翻译为 PyQt6

import sys
from PyQt5.QtWidgets import QApplication, QWidget
from PyQt5.QtCore import QEvent, Qt

class AppDemo(QWidget):
    def __init__(self):
        super().__init__()
        self.resize(800, 400)
        self.installEventFilter(self)
        
    def eventFilter(self, QObject, event):
        if event.type() == QEvent.MouseButtonPress: # <-- No longer work in PyQt6
            if event.button() == Qt.RightButton: # <-- Becomes event.button() == Qt.MouseButtons.RightButton
                print('Right button clicked')           

        return True

if __name__ == '__main__':
    app = QApplication(sys.argv)

    demo = AppDemo()
    demo.show() …
Run Code Online (Sandbox Code Playgroud)

python enums pyqt qevent pyqt6

8
推荐指数
1
解决办法
5424
查看次数

PyQt6中的QtDesigner在哪里?

我找到bindings/QtDesigner目录,但里面有所有.sip文件。

在pypi 的软件包网站上,它说

sip-install工具还将安装 sdist 包中的绑定,但允许您配置安装的许多方面。

sip-install需要一个名为 的文件pyproject.toml,但只有一个QtDesigner.toml,如果我将其重命名为 ,它就无法运行pyproject.toml

sip-install: pyproject.toml: the '[tool.sip.metadata]' section is missing
Run Code Online (Sandbox Code Playgroud)

的内容QtDesigner.toml

# Automatically generated configuration for PyQt6.QtDesigner.

sip-version = "6.0.1"
sip-abi-version = "13.0"
module-tags = ["Qt_6_0_0", "Qt_6_0_0", "Linux", "Qt_6_0_0", "Qt_6_0_0", "Linux", "Qt_6_0_0", "Qt_6_0_0", "Linux", "Qt_6_0_0", "Qt_6_0_0", "Linux"]
module-disabled-features = ["PyQt_WebChannel", "PyQt_OpenGL_ES2", "PyQt_WebChannel", "PyQt_WebChannel", "PyQt_OpenGL_ES2", "PyQt_WebChannel"]
Run Code Online (Sandbox Code Playgroud)

qt-designer pyqt6

7
推荐指数
2
解决办法
2万
查看次数

模块“PyQt6.QtWidgets”没有属性“QDesktopWidget”

我尝试运行此代码,但它总是收到此 AttributeError,我搜索了很多网站但没有任何答案。

QtWidgets.QDesktopWidget().availableGeometry().center()
AttributeError: module 'PyQt6.QtWidgets' has no attribute 'QDesktopWidget'
Run Code Online (Sandbox Code Playgroud)

我的代码:

from PyQt6 import QtCore, QtGui, QtWidgets

class Ui_Form(object):
    def center(self):
        qr = Form.frameGeometry()
        cp = QtWidgets.QDesktopWidget().availableGeometry().center()
        qr.moveCenter(cp)
        self.move(qr.topLeft())
Run Code Online (Sandbox Code Playgroud)

我正在使用 PyQt6 版本 6.1.0,Python 3.9.5

python pyqt python-3.x python-3.9 pyqt6

7
推荐指数
1
解决办法
6882
查看次数

PyQt6 的“QMessageBox.Yes”替代方案

我正在尝试将我的脚本从 PyQt5 移植到 PyQt6。由于这个答案,我已经弄清楚如何移植大部分内容,但是,我遇到了一个问题。

我发现 PyQt6 使用QtWidgets.QMessageBox.StandardButtons.Yes而不是 PyQt5QtWidgets.QMessageBox.Yes.

但是,当检查用户在 QMessageBox 打开后是否按下“是”时,替换QtWidgets.QMessageBox.YesQtWidgets.QMessageBox.StandardButtons.Yes不起作用(请检查下面的示例)。


例子:

PyQt5:

reply = QtWidgets.QMessageBox()
reply.setText("Some random text.")
reply.setStandardButtons(QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No)

x = reply.exec_()

if x == QtWidgets.QMessageBox.Yes:
    print("Hello!")
Run Code Online (Sandbox Code Playgroud)

打印“你好!” 这里工作正常。(16384 == 16384)

PyQt6:

reply = QtWidgets.QMessageBox()
reply.setText("Some random text.")
reply.setStandardButtons(QtWidgets.QMessageBox.StandardButtons.Yes | 
                         QtWidgets.QMessageBox.StandardButtons.No)

x = reply.exec()

if x == QtWidgets.QMessageBox.StandardButtons.Yes:
    print("Hello!")
Run Code Online (Sandbox Code Playgroud)

“你好!” 这里根本不打印。(16384 != StandardButtons.yes)


我知道我可以这样做:

x = reply.exec()

if x == 16384:
    print("Hello!")
Run Code Online (Sandbox Code Playgroud)

因为,按“是”后,QMessageBox 等于 …

python pyqt pyqt5 pyqt6

6
推荐指数
2
解决办法
7380
查看次数

PyQt6(没有pyrcc)如何提供资源?

PyQt6 的文档指出

\n
\n

对 Qt\xe2\x80\x99s 资源系统的支持已被删除(即没有pyrcc6)。

\n
\n

鉴于此,应该如何为 PyQt6 应用程序提供资源?

\n

python resources pyqt pyrcc pyqt6

6
推荐指数
2
解决办法
9556
查看次数

如何修复 PyQt6-tools 安装错误?

我想用 PyQt6 创建我的小型 GUI 应用程序。我已经安装了 PyQt6,但我还必须安装 PyQt6-tools。因此,当我尝试获取它时,出现以下错误:

C:\Users\egorl>pip install pyqt6-tools
Collecting pyqt6-tools
  Using cached pyqt6_tools-6.1.0.3.2-py3-none-any.whl (29 kB)
  Using cached pyqt6_tools-6.0.3.3.2-py3-none-any.whl (29 kB)
  Using cached pyqt6_tools-6.0.2.3.2-py3-none-any.whl (29 kB)
Collecting pyqt6==6.0.2
  Using cached PyQt6-6.0.2.tar.gz (940 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... error
  ERROR: Command errored out with exit status 1:
   command: 'C:\Users\egorl\AppData\Local\Programs\Python\Python310\python.exe' 'C:\Users\egorl\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py' prepare_metadata_for_build_wheel 'C:\Users\egorl\AppData\Local\Temp\tmpjhw74rau'
       cwd: C:\Users\egorl\AppData\Local\Temp\pip-install-yqby2el1\pyqt6_1bb69b3deb294f56858c9f93a5b67097
  Complete output (29 lines):
  Traceback (most recent call last):
    File "C:\Users\egorl\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py", line 156, in …
Run Code Online (Sandbox Code Playgroud)

python pip pyqt pyqt6

5
推荐指数
2
解决办法
2万
查看次数

PyQt6 中 setWindowFlags 的模拟是什么?

在尝试将 pyqt5 代码迁移到 pyqt6 时,我遇到了 setWindowFlags: self.setWindowFlags(Qt.WindowStaysOnTopHint)returns an error: AttributeError: type object 'Qt' has no attribute 'WindowStaysOnTopHint' 的问题。那么 PyQt6 中有哪些相似之处呢?

python pyqt6

5
推荐指数
1
解决办法
2743
查看次数

标签 统计

pyqt6 ×10

python ×8

pyqt ×7

enums ×2

pyqt5 ×2

apple-m1 ×1

arm64 ×1

mach-o ×1

pip ×1

pyrcc ×1

python-3.9 ×1

python-3.x ×1

qevent ×1

qt ×1

qt-designer ×1

resources ×1