pyside

QMetaObject::invokeMethod doesn't find methods with parameters

跟風遠走 提交于 2019-11-28 07:46:31
问题 This is a follow up of QMetaObject::invokeMethod doesn't find the method. Invoking a method without paramters works. But extending the previous question to methods with parameters brings me back to failure again. See the following example script in Python: from PySide import QtCore class Example(QtCore.QObject): def __init__(self): super().__init__() @QtCore.Slot() def dup(self): beep('dup-class') @QtCore.Slot(str) def beep(self, text): print(text) @QtCore.Slot() def dup(self): beep('dup

Convert numpy array to PySide QPixmap

久未见 提交于 2019-11-28 06:28:41
I want to convert an image into a NumPy array to a PySide QPixmap, so I can display it (EDIT: in my PySide UI). I already found this tool: qimage2ndarray , but it only works for PyQt4. I tried to change it to get it working with PySide, but I would have to change the C part of the tool and I have no experience with C. How can I do this or are there any alternatives? One alternative is to just use PIL library. >>> import numpy as np >>> import Image >>> im = Image.fromarray(np.random.randint(0,256,size=(100,100,3)).astype(np.uint8)) >>> im.show() You can look at the QPixmap constructor at http:

problem displaying sympy rendered svg in python

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-28 04:41:28
问题 I have the following program which uses sympy and svgmath to render a user's algebraic expression. It nearly works but there are a few issues: The svg is not actually produced until the program exits so obviously cannot be diplayed. Is there a way to improve the performance (not looking up 'svgmath.xml' every time etc.)? Does an actual svg file need to be produced? Can svgmath pass output directly to the QSvgWidget? Many thanks and best wishes. from __future__ import division import sys

matplotlib and Qt: mouse press event.key is always None

别等时光非礼了梦想. 提交于 2019-11-28 04:29:17
问题 I embedded a matplotlib figure in a Qt (PySide) application and I would like to respond to mouse click events in combination with modifier keys (e.g. shift and control). In the code below I used the canvas mpl_connect method to connect 'button_press_event' to a dummy handler that prints the value of event.key. This value is always 'None' even if I press a modifier key during the mouse click. How can I get the state of modifier keys in a matplotlib mouse event handler when embedding a

Unit and functional testing a PySide-based application?

烈酒焚心 提交于 2019-11-28 04:00:55
I'm building a PySide 1.1.0-based application, and have been looking for good examples to look at for unit and functional testing my application. I want to be able to do functional testing of the UI (simulating clicks, key presses, etc), unit testing of UI slots that alter the layout of the UI (presumably using a partially-mocked sender and receiver), as well as unit testing of code that involves widgets, but without requiring any windows to be rendered. As one example, I dynamically create submenus of one menu in the menubar when an item is added to a model (QAbstractItemModel-derived object)

Why does PySide implicitely create object members from class members for Signals?

不想你离开。 提交于 2019-11-28 02:05:58
On the PySide signals and slots page it says: "Signals are runtime objects owned by instances, they are not class attributes". Apparently the QObject constructor looks in the class attributes for Signals and copies them to the object instance. This is confirmed by my test program. from PySide import QtCore class Klass(QtCore.QObject): lst = [] sig = QtCore.Signal(str) def main(): obj1 = Klass() obj2 = Klass() print "id: obj1.lst = {}, obj1.sig = {}".format(id(obj1.lst), id(obj1.sig)) print "id: obj2.lst = {}, obj2.sig = {}".format(id(obj2.lst), id(obj2.sig)) print "id: klass.lst = {}, klass

How QApplication() and QWidget() objects are connected in PySide/PyQt?

大城市里の小女人 提交于 2019-11-28 01:52:54
How QApplication() and QWidget() are connected? This is an example code that I copied, it creates QApplication object and QWidget object, but there is no link between the two objects. I expected something like app.setWidget(did) to teach PySide/PyQt controller about the widget that was created. # http://zetcode.com/gui/pysidetutorial/firstprograms/ # 1. PySide.QtGui is the class import sys from PySide import QtGui # 2. setup the application app = QtGui.QApplication(sys.argv) # 3. create the widget and setup wid = QtGui.QWidget() wid.resize(250, 150) wid.setWindowTitle('Simple') # 4. Show the

convert a list of delimited strings to a tree/nested dict, using python

落爺英雄遲暮 提交于 2019-11-27 21:56:16
问题 I am trying to convert a list of dot-separated strings, e.g. ['one.two.three.four', 'one.six.seven.eight', 'five.nine.ten', 'twelve.zero'] into a tree (nested lists or dicts - anything that is easy to walk through). The real data happens to have 1 to 4 dot-separated parts of different length and has 2200 records in total. My actual goal is to fill in the set of 4 QComboBox'es with this data, in manner that the 1st QComboBox is filled with first set items ['one', 'five', 'twelve'] (no

Use keyPressEvent to catch enter or return

你离开我真会死。 提交于 2019-11-27 18:30:02
问题 I have a simple form with some combos, labels, buttons and a QTextEdit. I try to catch the enter or return key with keyPressEvent, but for some reason I'm not able to. The ESC key however, that I also use, is recognized. Here's a piece of the code: def keyPressEvent(self, e): print e.key() if e.key() == QtCore.Qt.Key_Return: self.created.setText('return') if e.key() == QtCore.Qt.Key_Enter: self.created.setText('enter') if e.key() == QtCore.Qt.Key_Escape: self.cmbEdit = not(self.cmbEdit) if

How do i resize the contents of a QScrollArea as more widgets are placed inside

雨燕双飞 提交于 2019-11-27 14:30:37
问题 I have a QScrollArea Widget, which starts empty; It has a vertical layout, with a QGridLayout, and a vertical spacer to keep it at the top, and prevent it from stretching over the whole scroll area; Elsewhere in the program, there is a QTextEdit, which when changed, has its contents scanned for "species" elements, and then they are added to the QGridLayout. Any species elements which have been removed are removed too. This bit works; I have turned the vertical scrollbar on all the time, so