You need to retrieve the current cursor from the text-edit: cursor = self.recipient.textCursor() print('%s' % (cursor.selectedText())) But note that this cursor is only a copy. If you make changes to it, those changes won't immediately update the text-edit. To do that, you need to reset the cursor, like this: #...

setStrikeOut returns void and you should not pass it as the argument for setFont. You should pass an instance of QFont there. It would be better to retrieve the font of the item in question, set its strikeout property, and then set this revised QFont as the new font of...

I'm guessing accepted is always False then. And why are you reopening the pop up? If you ignore the event it will never close in the first place. Do you need the lambda function? If not, something like this seems simpler: class PopUp_Window(QWidget): def __init__(self, parent): self.parent = parent self.accepted...

From the official documentation: PySide.QtGui.QLayout.setContentsMargins() sets the width of the outer border on each side of the widget. This is the width of the reserved space along each of the PySide.QtGui.QBoxLayout ‘s four sides. PySide.QtGui.QBoxLayout.setSpacing() sets the width between neighboring boxes. (You can use PySide.QtGui.QBoxLayout.addSpacing() to get more space at...

It turns out that Python garbage collector was grabbing the reference and then PySide was trying to clean up the same reference. The solution was to implicitly hold a reference to said object in python. In our case it was a model we attached to QT. Within a class that...

QGridLayout::addLayout has a fourth (optional) parameter alignment. The alignment is specified by alignment. The default alignment is 0, which means that the widget fills the entire cell. So instead of setting the alignment of the QVBoxLayouts, set it when adding the layouts. def create_layout(self): .... mainLayout.addLayout(radioButtonSetALayout,0,0,QtCore.Qt.AlignTop) mainLayout.addLayout(radioButtonSetBLayout,0,1,QtCore.Qt.AlignTop) self.setLayout(mainLayout) ...

The solution is to simply avoid connecting the directoryChanged signal to the slot that updates the images. Instead, just set a flag whenever any changes occur, and then periodically check the flag to see if any updates are needed (this can be done with a simple timer mechanism). Here's a...

It's actually a silly error - the module is named PySide (with capital P and S letters), not pyside. Running import PySide should do the trick. To figure this out, I used Sublime and a couple of cool plugins. I have IPython and all its dependencies installed, mainly from Christoph...

According to the docs, the variant of QWidget.render that has a QPainter as its first parameter expects a mandatory targetOffset of type QPoint as its second parameter. If I add an empty point it works for me (although the tree widget is printed very small). painter.begin(printer) try: self.view.render(painter, QtCore.QPoint()) finally:...

You're creating a model for each item. That's wrong. You should use .appendRow/.insertRow on an item to add child items. As for your loops, I'd probably use a recursive method to populate the tree. Here is what I'd do: from PySide.QtGui import * import sys import types class MainFrame(QWidget): def...

This is easy to do with Tool Buttons. In Qt Designer: Create the tool buttons and set the text Put them in a horizontal layout Add a horizontal spacer to the beginning and/or the end of the layout Optionally, you could also: Set a minimum width/height Change the size-policy of...

The menu popup delay is not a fixed value, as it will depend on the current style. There is no way to set it programmatically. The Qt way to modify style hints for existing styles is via QProxyStyle. However, even that is not guaranteed to work for user-defined or third-party...

The problem is caused by the way you are using the queue. All the threads start and begin their tasks normally, up until the queue becomes empty. At that point, the first thread to finish terminates, but the other four threads are left waiting for an item to be returned...

Turns out the CustomizeWindowHint flag needs to be set before the WindowCloseButtonHint flag can be changed. The full code is: # enable custom window hint self.setWindowFlags(self.windowFlags() | QtCore.Qt.CustomizeWindowHint) # disable (but not hide) close button self.setWindowFlags(self.windowFlags() & ~QtCore.Qt.WindowCloseButtonHint) ...

I only have PyQt5 available for testing, but was able to reproduce your problem with it. When defining the layout in create_layout, buttonGroup1 and buttonGroup2 are deleted on return. You need to store these variables for them to exist after method return. For example this can be done by adding...

First of all you do not want to react immediately when a radio button is clicked, so you do not need to connect to their clicked signal. Instead the radio buttons (which are automatically exclusive within the same parent) can be selected by the user and at the moment the...

Never use __del__ unless you really, really know what you're doing. If you want to save things on exit, reimplement the closeEvent of the main window: class MainFrame(QWidget): ... def closeEvent(self, event): pickle.dump(progress, open("pickle_file.p", "wb")) ...

This looks like a PySide bug, as the same code works perfectly fine in PyQt. The bug seems to be in the QMovie constructor, which does not read anything from the device passed to it. A work-around is to set the device explicitly, like this: import sys from PySide import...

This seems to happen because, unlike Qt, PySide/PyQt determines the context at runtime. In your example, the context will (I think) resolve to QApplication at runtime, whereas the pyside/pyqt lupdate tools will hardcode it as app. The tools only do static analysis of the source code, and so I suppose...

You cannot override QLineEdit.copy or QLineEdit.paste in such a way that they will be called internally by Qt. In general, you can only usefully override or reimplement Qt functions that are defined as being virtual. The Qt Docs will always specify whether this is the case, and for QLineEdit, there...

Looks to me like it's a problem of using super with multiple inheritance. It picks one of the parents in a certain order to use. For example, super(Error_Popup,self).__init__(parent) only calls one of the parents __init__ methods. You have to manually call all of them. When calling methods or accessing variables,...

This can be done with standard python introspection techniques: for name in dir(QtGui.QPalette): if isinstance(getattr(QtGui.QPalette, name), QtGui.QPalette.ColorGroup): print(name) and the same can be done with QtGui.QPalette.ColorRole. But note that this will produce a few extra items that you might not be expecting. There are NColorGroups and NColorRoles. which give the...

The static functions like getSaveFileName will always use a native dialog, unless you include DontUseNativeDialog in the options argument. On the other hand, the QFileDialog constructor will always create an instance of Qt's built-in file dialog, no matter what options are set. You can change the file-mode to get the...

In Python, variable names are references to objects so all these different expressions actually refer to the same object ie the same data in memory. There is no duplication of objects, although there is duplication of references. So in your example, A.childItems[0], C.parentItem, and D.parentItem are all references to the...

It seems that the treatment of signals with default parameters (such as triggered and clicked) is different in PySide to what it is in PyQt. The former won't allow any positional arguments in the receiving slot, but the latter will happily throw away unused parameters without complaint. In both PySide...

Since it looks like you're not using threads, it may be that all that's required is to call processEvents after updating the progress bar, like this: self.prog_QProgressBar.setValue(progressInt) QtGui.qApp.processEvents() However, the effectiveness of this may depend on how long it takes the process to produce the output. All that the processEvents...

I think I found the problems: The PySide build apparently needs a python ..3.4.so shared library and not a static (.a) library see http://qt-project.org/forums/viewthread/49955. The solution was now to uninstall Python $ pyenv uninstall 3.4.2 Then reinstall Python with shared library support (see also https://github.com/yyuu/pyenv/issues/82): $ env PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install...

You connected btnConnect to both connectserver and disconnect, so when you click it, it will connect and then immediately disconnect the socket. If you try to send data to a closed socket, it will raise a bad file descriptor error....

At the moment, the PySide QUiLoader class doesn't have a convenient way to load widgets into to an instance of the top-level class like the PyQt uic module has. However, it's fairly easy to add something equivalent: from PySide import QtGui, QtCore, QtUiTools class UiLoader(QtUiTools.QUiLoader): _baseinstance = None def createWidget(self,...

Usually this error means that PySide is either unable to find the Qt DLLs, or the ones it did find are not the right version and do not have some of the expected symbols. Do you have some other set of Qt libraries on your system in the PATH somewhere?...

The timer posts a QTimerEvent, but there is no event-loop running in the thread to process it. So you need to do something like this: def run(self): timer1 = QTimer() timer1.singleShot(1000, self.alarm_goes1) print "Timer 1 Start" timer1.start() # start the clock clock = QTimer() clock.start(1000) clock.timeout.connect(self.tick) # start the thread's...

I found a satisfying explanation here. Apparently, emitting a signal of type DirectConnection is equivalent to a direct function call. So the GUI is after all updated on a Worker thread when both signals are DirectConnect-ed. As mentioned on my other question, threads are not allowed to change the GUI....

No, that won't work. What you should do is install the 32 bit python as well and create the "other" installer starting the creation process with that. It is possible to have both the 32 and the 64 bit version of the same Python major.minor version on the same machine....

In one project i had to enable one module to do a callback to my Mainwindow module. The Controller of the Mainwindow view starts a new subprocess and retrieves the stdout out as well as the callback as soon as the program is terminated. I managed this in the following...

I figured it out... the answer was in the documentation after all: https://docs.python.org/3/library/multiprocessing.html#pipes-and-queues In particular: They differ in that Queue lacks the task_done() and join() methods introduced into Python 2.5’s queue.Queue class. In my case, the solution seems to be adding this to the shutdown code: self.imgbuffer.cancel_join_thread() ...

As per the README onboard exposes a DBUS service to allow applications to toggle's its visibility. You probably want to do this by adding something like before and after the getText call. E.g. msg = QtDBus.QDBusMessage.createMethodCall('org.onboard.Onboard', '/org/onboard/Onboard/Keyboard','org.onboard.Onboard.Keyboard' 'org.onboard.Onboard.Keyboard.Show') QtDBus.QDBusConnection.sessionBus().send(msg) text, ok = QtGui.QInputDialog.getText(self, 'Input Dialog', 'Enter your name:') msg2 =...

Inspired by @ekhumoro, I referred to Signals and Slots Across Threads of QT documentation and found that there were many different connection types in QT. Understanding these types, all is clear. Replace the above code: dlg.ForceTermimateSignal.connect(testThread.finished) with: dlg.ForceTermimateSignal.connect(teshThread.finished, type=Qt.DirectConnection) then, everything works as expected....

I can't test this myself, but try: gettext.install('myapp', unicode=True) Or if that doesn't work, then try: _ = gettext.translation('myapp').ugettext The problem appears to be that the default in Python2 is for gettext to return bytes rather than unicode....

The most likely problem is that the JavaScript just isn't loaded yet. Adding time.sleep() calls doesn't help for that, those will also block the Qt event loop from continuing, not just your Python code. Try waiting for the page to have fully loaded instead, for example (using the loadFinished signal:...

I think my problem was related to the style in which I was connecting the signal and slot. I found this great post that walks you through the new style. I created a few variables before the MyLineEdit's constructor. Then I used those variables in the tab_event function. Then I...

By default Qt application implicitly quits when the last window is closed. To prevent it, you can use setQuitOnLastWindowClosed in QGuiApplication. app = QtGui.QApplication(sys.argv) app.setQuitOnLastWindowClosed(false) ...

You're right, your problem is, that your object is not deleted. You delete only the reference self.new_thread. The problem is in this line: self.new_thread = thread_worker(self) The reason for this is that the parent self of the thread is alive. As long as parent stays alive, the object self.new_thread is...

Yes, Pylab is a mode of IPython which starts an event loop for the IPython front end so that you can interact at the IPython command line with your GUI. Here's an simple example of code which will run with or without Pylab. import sys from PySide import QtGui app...

The hasIndex function just performs bounds-checking. If the row or column arguments are less than zero, or outside of the range of the row or column count of the parent index, it will return False; otherwise, it will return True. Also, in the example implementation, the index method does not...

You have misunderstood how QFileDialog works. The functions getOpenFileName, getSaveFileName, etc are static. They create an internal file-dialog object, and the arguments to the function are used to set properties on it. But when you use the QFileDialog constructor, it creates an external instance, and so setting properties on it...

vahancho explained the reason nicely in his answer and mentioned to override QProgressBar.text(). Fortunately this is straightforward in Python and I know how to do it. from PySide import QtGui, QtCore class MyProgressBar(QtGui.QProgressBar): """ Progress bar in busy mode with text displayed at the center. """ def __init__(self): super().__init__() self.setRange(0,...

After a few hours of extensive googling I finally figured it out. You can create a borderless window using QtGui.QMainWindow(parent=None, flags=QtCore.Qt.Popup) and then find the location of the icon with icon.geometry().center() and finally move the window there with window.move(icon_point). There is some hackery involved in deciding how to place the...

By making the Window a separated QWidget I'm able to instantiate it in the main window and pass and extra argument(item) which will be a instance attribute. class MainFrame(QWidget): def __init__(self): self.popup_windows = [] # to store the pops def display_popup_window(self, item): # item is the reference item that it's...

You need to pass the function object when connecting the signal, so get rid of the parentheses: self.folders_lv.customContextMenuRequested.connect(self.showMenu) Also, in the showMenu slot, you probably want: menu.popup(self.folders_lv.viewport().mapToGlobal(pos)) ...

self.tableWidget.itemDoubleClicked.connect(self.OpenLink) def OpenLink(self,item): if item.column() == 1: webbrowser.open('www.google.com') This is how I solved it in my program, item.text() is the text in the cell, item.row() is it's row number and item.column() the column number....

One way is to make your own model (derived from QAbstractTableModel) and then in the data method convert floating point numbers to the desired precision with '{.xf}'.format(number) or similar. This should also lift the edit restrictions. When you retrieve the data from the model you would have to convert to...

If you're using an item delegate, the initial text shown in the editor will be taken from the model, and any existing text will be overwritten. To control what happens before and after editing, reimplement the setEdtorData and setModelData methods of the item delegate: class Delegate(QtGui.QStyledItemDelegate): def createEditor(self, parent, option,...

So, after much struggle, I tried using py2exe, which also failed, and then switched to cx_freeze. After getting it to compile with cx_freeze, it spit out an error message, basically telling me which part of my code didn't have the needed dlls. It turns out, for some reason, SeaBorn was...

The second example works because it effectively becomes a subclass of the top-level class from Qt Designer. By contrast, the first example uses composition rather than subclassing, which puts all the gui elements inside an internal namespace. The Main class is just a container that acts as the parent of...

This won't work, because QStandardItem.text isn't a virtual function. As you've already discovered, overriding a non-virtual function is mostly useless, because although it will work fine on the Python side, it won't be visible on the C++ side, and so it will never be called internally by Qt. However, in...

The answer is to simply use: current_locale = QtCore.QLocale() This will resolve to the system locale, unless the default locale has been explicitly re-set using QLocale.setDefault(). So the normal procedure would be: if necessary, set the default locale immediately after the QApplication is created. After that, any time a QLocale...

This basic script creates an UI containing a 160*10 QTable and a QPushButton. Every odd row, a checkbox is added in the cell of the 10th column. Clicking on the button displays a list of the state of all checkboxes. States: 0: Unchecked 2: Checked There is a state 1...

Qt stylesheets are very mighty for styling and I recommend them. With self.setStyleSheet('QTableView::item{background:black;} QTableView{gridline-color:black;}') instead of setPalette in your example you achieve black items and black grid lines of the table. You can do much more with style sheets, for example change the background of the item when selected. See...

You cannot do this if you are using the static functions with a native file-dialog. The native file-dialogs do not have the same API as the Qt file-dialog, so you can only set the properties that are available via the static function arguments - which means the caption, title, working-directory,...

That tutorial you mentioned is really not very helpful. There are indeed many approaches to undo-redo implementation for views, we just need to choose the simplest one. If you deal with small lists, the simpliest way is to save all data on each change and restore full list from scratch...

To expand all nodes below the given one, I would do it recursively in the following way (C++): void expandChildren(const QModelIndex &index, QTreeView *view) { if (!index.isValid()) { return; } int childCount = index.model()->rowCount(index); for (int i = 0; i < childCount; i++) { const QModelIndex &child = index.child(i, 0);...

The itemClicked signal is not a good choice for handling treewidget checkboxes. On the one hand, it gives false positives when not clicking on the checkbox part of an item; and on the other hand, it gives false negatives when the checkbox is toggled using the keyboard. I think the...

You could use a statemachine. state no Printer state Printer detected state Printer active With your QTimer you regularely check if lsusb finds the printer. If found, you change to detected, open the popup and change to state active. In state active you regularely check if the Printer still can...

You need to increase the column count of the model in order to show the second column: root_model = QStandardItemModel() root_model.setColumnCount(2) and you also need to add the row of child items as a list: def _populate_tree(self, children, parent): for child in sorted(children): child_item = QStandardItem(str(child)) row = [child_item] if...