signals-slots

PyQt5 connection doesn't work: item cannot be converted to PyQt5.QtCore.QObject in this context

旧街凉风 提交于 2019-12-19 03:40:10
问题 I am trying to connect a signal from a created object and am getting an error. Here is a simplified version of my code: class OverviewWindow(QMainWindow): def __init__(self, projectClusters, users, contributorDict, userLastRevPerProj): QMainWindow.__init__(self) # Code.... def createUserNodes(self): userNodes = {} nodeSpread = 50 yPos = -400 nodeSpan = nodeSpread + 100 width = (len(self.usersFilt) - 1) * nodeSpan xPos = 0 - (width / 2) for user in self.usersFilt: newItem = NodeItem(xPos, yPos

Create PyQt menu from a list of strings

喜欢而已 提交于 2019-12-18 10:56:16
问题 I have a list of strings and want to create a menu entry for each of those strings. When the user clicks on one of the entries, always the same function shall be called with the string as an argument. After some trying and research I came up with something like this: import sys from PyQt4 import QtGui, QtCore class MainWindow(QtGui.QMainWindow): def __init__(self): QtGui.QMainWindow.__init__(self) self.menubar = self.menuBar() menuitems = ["Item 1","Item 2","Item 3"] menu = self.menubar

How to declare New-Signal-Slot syntax in Qt 5 as a parameter to function

一世执手 提交于 2019-12-18 08:08:30
问题 How can I pass signal or slot (member-function, new syntax in Qt 5) as a parameter to function and then call connect ? e.g. I want to write a function that waits for a signal. Note : It is not compile - PointerToMemberFunction is my question. bool waitForSignal(const QObject* sender, PointerToMemberFunction??? signal, int timeOut = 5000/*ms*/) { if (sender == nullptr) return true; bool isTimeOut = false; QEventLoop loop; QTimer timer; timer.setSingleShot(true); QObject::connect(&timer,

How to communicate or switch between two windows in PyQt?

牧云@^-^@ 提交于 2019-12-18 04:25:12
问题 I am developing an application using python and Qt. I have designed 2 Main windows ie..QMainWindow (Not QWidget or QDialog) using Qt. Let it be. 1.LoginWindow -- LoginUI(Qt) 2.StuffWindow --- StuffUI First i should display Login Window. Then i should pass the username to StaffWindow (username needed for managing stuffs) StaffWindow should be shown and LoginWindow Should be Closed.. How can i achieve this..? Help me.. 回答1: Regardless of your description, I think your LoginWindow should be a

What are signals and slots?

孤街醉人 提交于 2019-12-17 23:32:31
问题 Can someone explain in simple terms the "signals and slots" pattern? 回答1: Signals and slots are a way of decoupling a sender (the signal) and zero or more receivers (the slots). Let's say you a system which has events that you want to make available to any other part of the system interested in those events. Rather than hard-wiring the code that generates event to the code that wants to know about those events, you would use a signals and slots pattern. When the sender signals an event

MainWindow object has no attribute 'connect'

僤鯓⒐⒋嵵緔 提交于 2019-12-17 21:15:31
问题 I wonder if someone could help me resolve this issue regarding slot connection in PyQt5. The following code snippet will show you what my problem is. class MainWindow(QMainWindow): def __init__(self): super(MainWindow, self).__init__() path = os.path.join(os.path.dirname(__file__), 'GUI/Main_GUI.ui') self.gui = loadUi(path) self.gui.button_1.clicked.connect(self.run.this) def _connect_my_slots(self, origin): self.connect(origin, SIGNAL('completed'), self._show_results) self.connect(origin,

Lifetime of object in lambda connected to pyqtSignal

爷,独闯天下 提交于 2019-12-17 17:04:12
问题 Suppose I have an object and want one of its methods to be executed when a PyQt signal is emitted. And suppose I want it to do so with a parameter that is not passed by the signal. So I create a lambda as the signal's slot: class MyClass(object): def __init__(self, model): model.model_changed_signal.connect(lambda: self.set_x(model.x(), silent=True)) Now, normally with PyQt signals and slots, signal connections don't prevent garbage collection. When a connected slot's object is garbage

Catch mouse button pressed signal from qComboBox popup menu

浪子不回头ぞ 提交于 2019-12-17 16:59:09
问题 I have made multi-select QComboBox . Items are checkable (every item have check box and text value). CheckBox is checked only when user click on it. What I want is to catch signal when user click on text value so I can set check box next to it checked. How to do that? This is how I set model to combo box: areas = ["Area one", "Area two", "Area three", "Area four"] model = QtGui.QStandardItemModel(5, 1)# 5 rows, 1 col firstItem = QtGui.QStandardItem("---- Select area(s) ----") firstItem

Catch mouse button pressed signal from qComboBox popup menu

狂风中的少年 提交于 2019-12-17 16:59:03
问题 I have made multi-select QComboBox . Items are checkable (every item have check box and text value). CheckBox is checked only when user click on it. What I want is to catch signal when user click on text value so I can set check box next to it checked. How to do that? This is how I set model to combo box: areas = ["Area one", "Area two", "Area three", "Area four"] model = QtGui.QStandardItemModel(5, 1)# 5 rows, 1 col firstItem = QtGui.QStandardItem("---- Select area(s) ----") firstItem

Qt signaling across threads, one is GUI thread?

瘦欲@ 提交于 2019-12-17 10:27:06
问题 What does it mean to move a object from one thread to another in Qt using moveToThread? Everything seems to work even before using moveToThread, which moves the object from one thread (GUI thread) to a another thread ( worked) and Qt:connect calls the appropriate slot on object. Is there any difference because of where the object lives, GUI thread or the worker thread? EDIT: I made a small program, but I don't understand how QThread works along with Signal and slot function, I would