天道酬勤,学无止境

pyqt4

pyqt4 mouse release event not working

Im trying to track a mousepress and mouserelease event but the mouse release event it not recognized. import sys, os from PyQt4.QtCore import * from PyQt4.QtGui import * class Widget(QWidget): def __init__(self, parent=None): QWidget.__init__(self, parent) self.btn = QPushButton("Add Line") self.gv = QGraphicsView() self.scene = QGraphicsScene(self) self.gv.setScene(self.scene) self.gv.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform) lay = QHBoxLayout(self) lay.addWidget(self.btn) lay.addWidget(self.gv) script_dir = sys.path[0] image_loc = os.path.dirname(script_dir) + '

2021-09-25 09:26:30    分类:问答    python   pyqt   pyqt4

PyQT4 Combobox 更改另一个组合框的列表 [关闭](PyQT4 Combobox changes the list of another combobox [closed])

问题 很难说出这里问的是什么。 这个问题模棱两可、含糊不清、不完整、过于宽泛或言辞激烈,无法以目前的形式合理回答。 如需帮助澄清此问题以便重新打开它,请访问帮助中心。 8 年前关闭。 我刚开始使用 pyqt4,并且一直在研究如何从另一个组合框更改组合框列表。 是否有某种类型的示例显示如何使用此方法。 我是否使用 if, else 语句来更改 combobox_2 的选项? 前任。 Combobox_1 有一个 1,2,3 的列表。 Combobox_2 有 a、b、c 或 d、e、f 或 g、h、i 的列表。 如果在 Combobox_1、Combobox_2 中选择了 1,它将显示 a、b、c。 如果在 Combobox_1 中选择了 2,则 Combobox_2 将显示 d、e、f。 如果在 Combobox_1 中选择了 3,则 Combobox_2 将显示 g,h,i。 谢谢 回答1 你想要做的是这样的: def __init__(self): ... self.items = {'1':['a','b','c'],'2':['d','e','f'],'3':['g','h','i']} self.Combobox_1.activated[str].connect(self.on_combo_activated) ... ... def on_combo_activated

2021-09-25 01:27:22    分类:技术分享    python   combobox   pyqt4   qt-designer   qcombobox

PyQT4 Combobox changes the list of another combobox [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 8 years ago. I just started using pyqt4 and am stuck on how to change a combobox list from another combobox. Is there a example of sometype that shows how to work this method. Do I use a if, else statement to change the option for combobox_2? ex. Combobox_1 has a list of 1,2,3. Combobox_2 has a list of a,b,c or d,e,f or g,h,i

2021-09-24 07:38:36    分类:问答    python   combobox   pyqt4   qt-designer   qcombobox

将 Matplotlib 作为自定义小部件嵌入 PyQt(Embed Matplotlib into PyQt as a custom widget)

问题 我试图将 python 中的 matplotlib 作为自定义小部件嵌入 Qt Designer,我在网上遵循了其中一条指令,我将小部件提升到 mplwidget.py 并将文件编码为以下代码 from PyQt4 import QtGui from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas from matplotlib.figure import Figure class MplCanvas(FigureCanvas): def __init__(self): self.fig = Figure() self.ax = self.fig.add_subplot(111) FigureCanvas.__init__(self, self.fig) FigureCanvas.setSizePolicy(self, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) FigureCanvas.updateGeometry(self) class MplWidget(QtGui.QWidget): def __init__(self): QtGui.QWidget.__init__(self) self

2021-09-24 06:20:19    分类:技术分享    qt   python-2.7   matplotlib   pyqt4

QThreadPool - How to interrupt / How to use wisely the waitForDone method

Background : I have a script that allows me to make spatial queries on a PostgreSQL database via an API coming from a private editor (I can't directly query the database). This API is working with python 3.2. To summarize very quickly, this script is used to download elements of this database in the desired geographical footprint. Depending of the zone, you can obtain between 1 to over 100 elements, each of them having very different sizes (from Ko to Go). The main window let you to set all options and then start the global process. When launched a console window appears letting you see what’s

2021-09-24 05:58:14    分类:问答    python   python-3.x   pyqt   pyqt4   qthread

在 pyqt4 中旋转像素图会产生不需要的翻译(Rotating a pixmap in pyqt4 gives undesired translation)

问题 我正在尝试编写一个简单的应用程序,在按下按钮时旋转 png 图像。 我一切正常,只是当图像旋转时,它会在东南方向偏离它的中心。 我原以为它没有绕着它的中心旋转,但它每旋转 45 度就会回到原点,这很奇怪。 在一个关键事件上,我只是调用: pixmap = pixmap.transformed(QtGui.QTransform().rotate(-self.rot), QtCore.Qt.SmoothTransformation) 有没有办法设置转换的原点以阻止图像四处移动? 回答1 一个简单的解决方案,如果您使用 QLabel 绘制 QPixmap,则将 QLabel 的对齐方式设置为AlignCenter 。 此外,为了避免在图像旋转的前 45 度期间初始调整 QLabel 的大小,可以将 QLabel 的最小大小设置为像素图的对角线值。 然后图像应该围绕其中心正确旋转,而不会出现任何不需要的来回平移。 下面我将演示如何在一个简单的应用程序中完成此操作: import sys from PyQt4 import QtGui, QtCore import urllib class myApplication(QtGui.QWidget): def __init__(self, parent=None): super(myApplication, self).__init__

2021-09-24 00:12:47    分类:技术分享    pyqt4

Strange behavior of QLineEdit widgets in QDialog, binding button function

I am new with programming in pyqt, so maybe i am wrong with this, but i have found that self.lineEdit on Enter pressed calls for button's function, even when self.handleKeyRelease is commented. This is minimum of code and first place where i have found that strange behavior. self.lineEdit = QtGui.QLineEdit(self.frame) # self.lineEdit.keyReleaseEvent = self.handleKeyRelease self.pushButton = QtGui.QPushButton(self.frame) self.pushButton.clicked.connect(lambda event: self._insertIntoCategories(db, self.lineEdit)) second place of this same behaviour are ,dynamically made, form-like widgets (there

2021-09-23 23:46:44    分类:问答    python   pyqt   pyqt4

Embed Matplotlib into PyQt as a custom widget

I was trying embed matplotlib in python into Qt Designer as a custom widget, i followed one of those instruction online, i promote the widget to mplwidget.py and i coded file as code following from PyQt4 import QtGui from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas from matplotlib.figure import Figure class MplCanvas(FigureCanvas): def __init__(self): self.fig = Figure() self.ax = self.fig.add_subplot(111) FigureCanvas.__init__(self, self.fig) FigureCanvas.setSizePolicy(self, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) FigureCanvas.updateGeometry

2021-09-23 22:58:06    分类:问答    qt   python-2.7   matplotlib   pyqt4

如何强制 PyQt5 用于 QObject 类?(How to force PyQt5 use for QObject class?)

问题 我正在使用 Python 3 和 PyQt5 开发一个小型图形应用程序。 在我使用的第一台计算机上,只安装了 PyQt5,我的代码中的一切都很好。 但是,当我想在安装了 PyQt4 和 PyQt5 的另一台笔记本电脑上运行我的代码时,出现以下错误: RuntimeError: the PyQt5.QtCore and PyQt4.QtCore modules both wrap the QObject class Python 解释器在从主文件调用的文件“ViewWindow.py”中定位错误。 由于我在这台笔记本电脑上有 PyQt4 和 PyQt5,并且因为我无法卸载 PyQt4(这太容易了...),我想知道是否可以强制使用 PyQt5.QtCore 或其他东西来避免这个问题. 我在这台笔记本电脑上的配置:Debian 8、Python3.4、PyQt4 和 5(没有特殊配置,从 Debian 存储库安装),IDE = Spyder。 我把文件main.py和ViewWindow.py第一行放在那里。 # main.py import sys import sqlite3 import ViewWindow from DataWindow import DataWindow from PyQt5.QtCore import QObject # I tried adding

2021-09-21 10:09:33    分类:技术分享    python   python-3.x   pyqt4   pyqt5   qobject

向图中添加导航工具栏(matplotlib 和 PyQt4)(Adding Navigation Toolbar to the Figure (matplotlib and PyQt4))

问题 我想在我的 PyQt4 GUI 中创建一个导航工具栏,但我无法让它工作,我必须承认我主要是复制粘贴了这段代码,但我并没有真正理解它。 如果您能告诉我如何添加 NavigationToolbar 并解释它是如何制作的,那就太好了。 先感谢您。 顺便提一句。 我看过这篇文章,但我相信它与我的不同,我不知道如何使用它。 from PyQt4 import QtGui from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas from matplotlib.figure import Figure class MplCanvas(FigureCanvas): def __init__( self ): self.fig = Figure() self.ax = self.fig.add_subplot( 111 ) FigureCanvas.__init__( self, self.fig ) FigureCanvas.setSizePolicy( self, QtGui.QSizePolicy.Expanding,QtGui.QSizePolicy.Expanding ) FigureCanvas.updateGeometry( self ) class

2021-09-21 03:22:07    分类:技术分享    python   python-2.7   user-interface   matplotlib   pyqt4