天道酬勤,学无止境

pyqt

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

Qt:QPushButton 被子进程阻塞(Qt: QPushButton is blocked by child process)

问题 鉴于以下代码 button = ... process = QProcess() button.clicked.connect(start_process) def start_process(): # Disable the button button.setEnabled(False) # This seems to have no effect (...) # This also has no effect, thus commented out. # QApplication.processEvents(QEventLoop.ExcludeUserInputEvents) # Execute the program in a blocking way process.execute('/usr/bin/libreoffice') # (...) as right now, while libreoffice is running and I click the button # no animation is taking place, but the click !! is getting registered !! # If I terminate libreoffice, these clicks are executed and this function

2021-09-25 02:14:58    分类:技术分享    python   qt   process   pyqt   pyside

Drag Drop Operation in QTreeWidget not copying the dropped item

I want to copy an item from a QTreeWidget-parent under another parent via a drag & drop mouse operation. For this, I have implemented the dropEvent() and am setting the dropAction to Qt.CopyAction. But anyway, the item I am dropping is not being copied under the new parent. E.g. -> dragging the user "schmidt" under the group "LON". Expected behaviour: the item I am dropping is being copied under the new parent. (e.g. user "schmidt" will be added under group "LON"). Full working code example: #!/usr/bin/env python3 # coding = utf-8 import sys from PyQt5 import QtCore, QtGui, QtWidgets class

2021-09-24 19:51:04    分类:问答    python   pyqt   drag-and-drop   pyqt5   qtreewidget

PyQt5 : QMediaPlayer can't replay audio from QBuffer

I have a QBuffer in RAM with a temporary wav file, and I want to let the user listen it from any point as many times as (s)he want. But, it only allows playing it once, and doesn't allow replaying it. If I play the audio from a file (QUrl.fromLocalFile), it can replay it. What's the difference? How to fix it? 1) To play the wav file from RAM I use the following code: data = b"" with open(fname, "rb") as file: data = file.read() buf = QBuffer() buf.setData(data) #For debugging. Real buffer is filled differently. buf.open(QIODevice.ReadOnly); self.mediaPlayer=QMediaPlayer(self) self.mediaPlayer

2021-09-24 10:34:30    分类:问答    python   pyqt   pyqt5   qmediaplayer   qbuffer

PyQt: How to move widgets inside QStackedWidget object?

I've created window with button named "First", the window shows me next button named "Second" after clicking on the button "First", but button "Second" isn't moved by: self.b2.move(50,50) Whats the problem? import sys from PyQt5 import QtWidgets class Window(QtWidgets.QMainWindow): def __init__(self): super().__init__() self.init_UI() def init_UI(self): self.Centr= QtWidgets.QWidget() self.setCentralWidget(self.Centr) self.window = QtWidgets.QStackedWidget(self.Centr) self.b1 = self.addButton() self.window.addWidget(self.b1) self.b2 = self.addButton_2() self.b2.move(50,50) self.window

2021-09-24 09:48:29    分类:问答    python   qt   pyqt

PyQt5 Gui Thread to worker Thread signal/Slot

I am trying to make a simple communication between a worker thread, in this case it is called WorkToDo via the PyQt5 Signals and Slots mechanism. I can reliably send data from the Worker to the Gui thread via this mechanism, but I cannot do the same to the gui thread. From my research I have found that this is due to the fact that I have overridden the run function with my own logic. My question, is there any way to manually handle the execution of signals in the worker thread? Is there a better way to accomplish this? EDIT: I am actually not overriding run as I do not see run listed in the

2021-09-24 09:16:58    分类:问答    python   pyqt   pyqt5   qthread

选择“X”关闭按钮时如何让 PyQt 窗口调用方法(How to have a PyQt window call a method when its "X" close button is selected)

问题 我正在尝试在选择 PyQt 窗口的“X”关闭按钮时调用一个方法。 轻快地,我有一个对象 QtGui.QWidget 的类,我希望它在使用“X”关闭按钮关闭窗口时调用它的一个方法,以便结束一些子进程。 这怎么可能? 代码如下所示。 我想调用的类interface的方法是stylusProximityControlOff() 。 此方法终止一个可能有点混乱的子进程,但这是一个单独的问题。 无论如何,我很感激有关在选择“X”时调用该方法的建议。 #!/usr/bin/env python """ spin, a small utility to assist in setting usage modes of laptop-tablet devices Usage: spin.py spin.py -h | --help spin.py --nogui Options: -h,--help : show this help message --nogui : non-GUI mode """ from docopt import docopt import os import sys import subprocess from multiprocessing import Process import time from PyQt4 import QtGui import

2021-09-24 06:11:25    分类:技术分享    window   pyqt   multiprocessing   terminate

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

Qt: QPushButton is blocked by child process

Given the following code button = ... process = QProcess() button.clicked.connect(start_process) def start_process(): # Disable the button button.setEnabled(False) # This seems to have no effect (...) # This also has no effect, thus commented out. # QApplication.processEvents(QEventLoop.ExcludeUserInputEvents) # Execute the program in a blocking way process.execute('/usr/bin/libreoffice') # (...) as right now, while libreoffice is running and I click the button # no animation is taking place, but the click !! is getting registered !! # If I terminate libreoffice, these clicks are executed and

2021-09-24 02:50:37    分类:问答    python   qt   process   pyqt   pyside

exe does not find dlls using pyinstaller with pyqt

When I use pyinstaller --windowed main.py on my program I get the following error when I run the resulting executable main.exe: This application failed to start because it could not find or load the Qt platform plugin "windows" in "". Reinstalling the application may fix the problem. The folder structure looks like this: main ├── PyQt5 | └── Qt | └── plugins | ├── iconengines | ├── imageformats | ├── platforms | └── printsupport ├── main.exe └── ... The error disappears when I change it to: main ├── iconengines ├── imageformats ├── platforms ├── printsupport ├── main.exe └── ... I suspect the

2021-09-24 01:33:38    分类:问答    python   pyqt   pyqt5   pyinstaller