FAQ Database Discussion Community


Inserting multiple QCheckBox into QTableWidget odd rows

python,pyqt,pyside,qtablewidget,qtablewidgetitem
I'm trying to create a table with 160 Rows, and then inserting a QCheckBox every odd number of rows, specifically on column 10. The problem is, i have to create 80 QCheckBox (one for each row, so they can be separately assigned by the user)... Creating one by one...

Resizable PyQt widget displaying an image with fixed aspect ratio

qt,pyqt,qimage
It is a common problem to display a QImage in a widget. While this can be done using QLabel.setPixmap, the resulting QLabel will have a fixed size equal to the size of the pixmap. It is possible to use setScaledContents to make QLabel scale the pixmap and allow for resizing....

Converting 2D screen coordinates to 3D Coordinates in PyQT

qt,3d,pyqt,2d,2d-3d-conversion
I am using PyQT for one of the first times, and I'm having trouble figuring out where a mouse click is in 3D space. Obviously it is not a perfect 1-to-1 mapping, but let's say that I click on a location (x, y, 0) on my QtGui. How can I...

Why does QTreeView not fire a Drop or Move event during drag and drop?

python,pyqt,qtreeview
I was attempting to figure out an answer to this question when I realized the events I'm looking for aren't occurring. import sys, new from PyQt4 import QtGui, QtCore class MainForm(QtGui.QMainWindow): def __init__(self, parent=None): super(MainForm, self).__init__(parent) self.model = QtGui.QStandardItemModel() for k in range(0, 4): rootItem = self.model.invisibleRootItem() parentItem = QtGui.QStandardItem(QtCore.QString("Parent:...

How can I center a label in the center of a QWizardPage?

python,qt,pyqt,pyqt4,wizard
I have a label: self.label = QtLabel(self) that is inside of a VBoxLayout. That I want to set in the center of a QWizardPage, no matter what size the window becomes. I managed to get it centered horizontally with: self.label.setAlignment(QtCore.Qt.AlignCenter) but I cannot seem to get it to center vertically...

OpenCV functions won't work on OpenCV window converted in PyQt GUI window

python,qt,opencv,image-processing,pyqt
I am using OpenCV for image processing and embedding the images in a PyQt GUI window. I have used the OpenCV code independently and it works fine. I can also create the following windows and objects in OpenCV and successfully convert them other color spaces via cv2.cvtColor then convert to...

Port C++ class to PyQt

python,c++,qt,pyqt,porting
I am trying to convert a Qt4 custom widget written in C++ to a Python 2.7 custom widget. However, I have not been able to figure out how QLabel(parent) would be written in Python. This is the original C++ code from the ".ccp" file: DocumentWidget::DocumentWidget(QWidget *parent) : QLabel(parent) { currentPage...

QVBoxLayout's 'setAlignment' method not working as expected

python,qt,pyqt,pyside,qvboxlayout
from PySide import QtCore from PySide import QtGui class UI(QtGui.QDialog): def __init__(self): super(UI,self).__init__() self.setWindowTitle('My UI Title') self.create_layout() def create_layout(self): mainLayout = QtGui.QGridLayout() radioButtonSetALayout = QtGui.QVBoxLayout() radioButtonSetBLayout = QtGui.QVBoxLayout() #radio button set A setALabel = QtGui.QLabel('Fruit') radioButtonA = QtGui.QRadioButton('Apple') radioButtonB = QtGui.QRadioButton('Pear') radioButtonSetALayout.addWidget(setALabel)...

Syntax highlighting not working from QMainWindow

qt,pyqt,qt4
I'm trying to implement syntax highlighting using PyQt4. The examples I've tried work fine, but as soon as I work it into an application the highlighting stops working. I've created a minimal example to recreate the issue below. I've removed all the regex except for the comment one: lines starting...

How to re-use variable

python,qt,user-interface,pyqt
This is my code in PyQt5: def path(self, Interface): p= str(QFileDialog.getExistingDirectory(self.pathTab1, 'Directory Path','', QFileDialog.ShowDirsOnly)) return (p) def enableBox(self, Interface, p): if p!= '': self.chkDedensification.setCheckable(True) if __name__ == "__main__": ui.enableBox(Interface, ??????) In the __name__=="__main__", where the ??????? are, I want/have to use 'p', but if I just type p, it says...

Still Freezing when using PyQt4 Thread

multithreading,pyqt,midi
Despite using a QThread, the GUI is still freezing (code posted at end) The space bar is hit which starts playing midi notes by creating the thread and emitting calls to the play function if self.playing is False: # PlayThread is initiated in PianoRoll when the space bar is hit....

PyQt Enable/Disable elements in a QComboBox

python,python-3.x,pyqt,pyqt4,qcombobox
I have a QComboBox that list all Windows' drive letters and let the user choose among them. During the execution, we need to enable or disable some of the letters (without removing them). Here is the basic code : all_letters = ["{}:".format(chr(i)) for i in range(90, 64, -1)] # Z:...

How to override Pyqt combobox ItemText method so it returns default python string instead of QString?

python,list,combobox,pyqt,pyqt4
When ever I do resos = [_ui.ComboBox.itemText(i) for i in range(_ui.ComboBox.count())] it is giving me list of [PyQt4.QtCore.QString(u'1280x720 from 1.316'), PyQt4.QtCore.QString(u'1920x1080 from 1.316'),] how would it be possible to override ComboBox's itemText method so that it only returns python string ? instead of doing string conversion in the list comprehension...

Qt (PyQt) globally available slots?

qt,pyqt
I have a fairly complex MVC structured application and I want a convenient way to update a QStatusBar from almost any part of it. My understanding is that I would have to pass around a lot of references to my QStatusBar or set up a bunch of signals in my...

Understanding MVC in a QAbstractTableModel

model-view-controller,pyqt,qtableview,qabstracttablemodel
I have some data which are represented by a class of my own ; to fix the ideas I give an example. class MyOwnModel(): def __init__(self, name="", number=0): self.name = name self.number = number I then have a list of such instances, that I want to represent in a QTableView....

Start a function from a thread. (GUI thread and QThread errors)

python,multithreading,process,pyqt,qthread
I've made routine with Python's threading module to run a subprocess and wait for it to finish. I do the threading with the following line : t1=Thread(target=self.routineFunction, args=(self, "file1.txt", "file2.txt", self.nextFunction)).start() Inside my function routineFunction(self,file1,file2,nextFunction) I call the next function to run once the subprocess has finished running. Everything works...

How do I change each pixel

python,image-processing,pyqt,qimage
I am new to Python and I still don't know what exactly Qimage's pixel returns (it seems to a tupel of rgb or rgba -the lack of type declaration doesn't help) I want to grab each each pixel and change it. newqim = QImage(imWidth, imHeight, QImage.Format_ARGB32) for xstep in range(0,...

How often are objects copied when passing across PyQt signal/slot connections?

python,pyqt,signals-slots,pyqt5
This interesting article evaluates how often are objects copied when passed across signal/slot connections in Qt. Basically, the outcome is that when passed by const reference in C++, objects are either not copied at all (for direct connections) or copied once (for queued connections). How about PyQt? Does the same...

How can I have an animated system tray icon in PyQt4?

python,qt,pyqt,pyqt4,system-tray
I am trying to create an animated systray icon for a pyqt4 app but am having trouble finding any examples in python. This is the closest I can find but it's in C++ and I don't know how to translate it over: Is there a way to have (animated)GIF image...

Can a QListWidget have groupings?

qt,pyqt,pyqt4,qlistwidget,qtreewidget
I currently have a QListWidget that displays many items that are user selectable (and dragable). In my application, when an item is checked it will be reordered above the unchecked items. The user can also drag/drop to adjust the order of the checked items. The problem the users have is...

Logging python errors on raspberry pi

python,linux,pyqt,raspberry-pi
I'm having a helluva time debugging a python app I've written for an embedded raspberry pi project I'm working on because it's using a TFT screen instead of a full monitor and has no monitor/keyboard, so i'm having to launch the python app via an icon on the TFT desktop...

PyQt4 setParent vs deleteLater

pyqt,pyqt4
I have a layout that I add a lot of custom widgets to with something like layout.addWidget(widget). Later I want to remove all those custom widgets and add new ones. I'm confused on the best way to do this when it comes to deleteLater and setParent(None). For example, here's my...

PyQt: QDataWidgetMapper doesn't show any data in widgets

python-3.x,pyqt,pyqt4
I have a AbstractItemModel that I want to map to some widgets. In the constructor of the window I have: print("creating model") self.model = Model(self.cluster) print("creating mapper") self.mapper = QtGui.QDataWidgetMapper() print("setting model") self.mapper.setModel(self.model) print("setting root index") self.mapper.setRootIndex(self.model.root_index()) print("setting index") self.mapper.setCurrentIndex(0) print("mapping widgets") self.mapper.addMapping(self.realNameLineEdit, 1) self.mapper.addMapping(self.emailLineEdit, 2)...

The event loop is already running

python,python-3.x,pyqt,pyqt4
I have the following 5 files: gui.py # -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui try: _fromUtf8 = QtCore.QString.fromUtf8 except AttributeError: def _fromUtf8(s): return s try: _encoding = QtGui.QApplication.UnicodeUTF8 def _translate(context, text, disambig): return QtGui.QApplication.translate(context, text, disambig, _encoding) except AttributeError: def _translate(context, text, disambig): return QtGui.QApplication.translate(context, text, disambig)...

WARNING: All changes made in this file will be lost

qt,user-interface,pyqt
So I have a general question. When you convert your .ui file into a .py file with pyuic, on the top part of the .py file it says: WARNING! All changes made in this file will be lost! Is is serious ? How will changes made in the file lost...

arange horizontal line of buttons in Pyside/PyQT/Qt

qt,button,layout,pyqt,pyside
I want to create a simple GUI with PySide/PyQt. In this GUI I want to have a raw with severeal push buttons and the length of the buttons I want to be proportional to its text label. Looking at QPushButton and QHBoxLayout I don't see a posibility this can be...

Refreshing a QWidget

python,qt,python-2.7,pyqt,vtk
I've been having this issue a lot of times. When I modify some properties of a QWidget after the widget.show(), the widget won't update. Most of the time, a mouse click or when the mouse leaves or enters the widget, the widget will be updated. However, if I leave the...

How to get groups and roles of a QPalette in PyQt/PySide?

pyqt,pyside,qpalette
Instead of "manually" defining lists groups and roles (in my code below), how can I query the PyQt/PySide application for these values? from PyQt4 import QtGui groups = ['Disabled', 'Active', 'Inactive', 'Normal'] roles = [ 'AlternateBase', 'Background', 'Base', 'Button', 'ButtonText', 'BrightText', 'Dark', 'Foreground', 'Highlight', 'HighlightedText', 'Light', 'Link', 'LinkVisited', 'Mid', 'Midlight',...

PyQt5 QSqlTableModel not updating changes to database

python,mysql,pyqt,pyqt5,qsqltablemodel
I have a PyQt5 Application connecting to a MySQL database. I made two views connected to the same model. The views pull in data from the database just fine. Any change I make to any field in one is reflected in the other. But it does not update the database....

PyQt 3.3.6: How to align text in a table?

python,pyqt
I have a table in which I put numbers (as a string) in a column. For some reason, it appears that numbers with 2 or more periods (i.e. 5.5.5) will align on the left side of the cell, while numbers with fewer periods (i.e. 55.5) will align on the right...

Disable cmd opening from GUI (PyQt)

python,user-interface,cmd,pyqt,pyqt5
I have a GUI (created with PyQt5 and py2exe). This GUI takes input data (shp, images..) and uses them as parameters in softwares (ie FME). Whenever I launch a task on a software through the GUi, a cmd opens. To launch the softwares, I use subprocess.Popen in my script with...

Creating check boxes dynamically inside the listview based on the layers loaded in QGIS

python-2.7,pyqt,pyqt4
I have a two list views named "Datacheckerlistview1" and "Datacheckerlistview2" in my gui. Now i had loaded layers in QGIS. Based on the number of layers loaded, i want check boxes to be created dynamically with the layer name inside the "Datacheckerlistview1"..( for ex: if there are 4 layers loaded,...

PyQt Not updating label

python,pyqt
I've created a simple application to transfer files using Paramiko and SFTP. I also wanted to have a statusbar (a QLabel) to inform the user when I'm downloading/uploading stuff. So, my function to upload looks something like this: def upload(self): self.statusLabel.setText('Uploading') local = str(self.uploadLineEdit.text()) filename = os.path.basename(local) remote = "/home/"...

PyQt5 resize only one child widget when window is resized

python,qt,layout,resize,pyqt
I'm building a GUI in PyQt5. Its structre will look like on the attached picture. What I need is to managed that when window is resized: Blue area resizes both horizontally and vertically Read and green areas resize only vertically purple area resizes only horizontally user can change size of...

Displaying an image on pyqt

python,image,pyqt
I'm trying to display an image in pyqt for my coursework. I'm attempting this in the Handle Question sub routine. here's a sample of it class IntegrationQuestions(QtGui.QMainWindow): def __init__(self, parent = None): from equation import IntQuestion, IntAnswer QtGui.QDialog.__init__(self, parent) self.setWindowTitle('Simple Integration') self.setMinimumSize(265,400) self.lbl1 = QtGui.QLabel("Integrate the equation below",self) self.lbl1.move(0,0) self.lbl1.resize(200,20)...

Pyqt - Add a QMenuBar to a QMainWindow which is in another class

python-3.x,pyqt,pyqt5
I have 2 classes : MainWindow() and Menubar(). MainWindow() is a QMainWindow and Menubar is a QMenuBar. I don't know how I can add the menu bar to the main window. With the QToolBar, I can make something like this : self.toolbar = Toolbar() self.addToolBar(self.toolbar) But with the QMenubar, there...

pyqt - Automatically update widget on user input

python-2.7,pyqt,pyqt4
Total pyqt novice here. Trying to automatically modify the widget to display different options when user selects certain option in combobox 2. IE if user selects 'Cliff Erosion' or 'Dune Erosion', I want the widget to refresh with additional comboboxes. Likewise, if they select back to 'Rising Tides' or 'Coastal...

Heights of QPushButton and QLineEdit differ under OS-X

qt,pyqt,pyside
I want to place a QPushButton and a QLineEdit in together one QTreeView cell by putting them in a container widget that has a QHBoxLayout. However, it doesn't look good, the button is taller than the line editor as you can see in my screen shot below. When the cell...

Pyqt: Graphics view next to another widget

python,layout,pyqt
I am trying to set up a graphics view next to a custom widget that acts as a container. The graphics view is taking up the entire window. I tried explicitly setting the size but that dose not seem to work. I also added another widget in place of the...

Line edits at 0 when not used? PyQt

python,pyqt
i'm in a situation where i take the user input and do some math operations.. The user selects an item from a combobox, and inputs a number in the line edit next to it. When he clicks ok, it returns (comboboxselectedvalue)+(lineeditvalue), it works, most of the time, my problem is,...

How to switch between two windows in python using PyQt

python,python-2.7,pyqt,pyqt4
I am working on some app. I wanted to create a toolbar that after having been clicked will open Settings window. However I don't know how to do it exactly. The way it is now is that i have a Toolbar icon connected to ShowSettings function. This function creates a...

Pyqt Embedding Graphics object in Widget

python,layout,widget,pyqt
So I have a main window. I use setCentralWidget to set it to a class I made called mainWindowWidget to handle the UI. I am now trying to add a graphics view widget I made to that but cannot seem to get anything to display. If I set the graphics...

pyqt - copying image to QClipboard crashing program

python,pyqt
I am writing a PyQt program which I want to be able to copy to the clipboard. Currently I have the following snippet copy the code (based on this: def copy_to_clipboard(self): application=QApplication(sys.argv) if not self.image.isNull(): application.clipboard().setImage(self.image) The code is copying the image, but every time it runs, the program crashes....

Error with thread in pyqt4

python,multithreading,pyqt,pyqt4
I have the problem. I made the thread and from there I want to open the new window. But it does not work. import sys from grab import Grab from PyQt4 import QtGui, QtCore class Requests(QtCore.QThread): def __init__(self, parent=None): QtCore.QThread.__init__(self, parent) def run(self): # here some comands self.emit(QtCore.SIGNAL("mysignal(QString)"), 'open') class...

Adding tools to Scribble app with PYQT4

python,pyqt,qgraphicsview,qgraphicsscene
I am trying to write an app which works as MS Paint or other simple graphics editor. My goal is to provide such funcionality as: different tools( drawing lines, figures etc.), posibility to change colors, width, size and undo/redo function. I thought that the easiest way to do it was...

How can I disable a QCheckBox WITHOUT triggering an event?

python,pyqt,qcheckbox
I am wondering if there is anyway to disable (setCheckState) on a check box (QCheckBox) in pyqt "WITHOUT" triggering an event? So it is simply a display change with the checkbox now unticked but not triggering the method I have it connected to. Thanks for any help. Would love a...

PyQt progress bar not updating or appearing until 100%

python,widget,pyqt,pyqt4
EDIT: There are a number of similar posts on PyQt4 progress bars not updating. They all focus on the issue of threads & where the program actually updates the window. Although helpful, my code was so structured that the replies were not practical. The accepted answer given here is simple,...

How to get function to run at specyfic time using python and PyQt not using Cron

python,qt,pyqt,periodic-task
I'm creating RSS app in PyQt and I'm trying to find a good way to program updates. I found this Executing periodic actions in Python but maybe there is Qt specific way to do this things. I know update period for each feed so I want to run update at...

Change the background color of some lines in QPlainTextEdit

pyqt
This does not work: def lineError(self): block= self.firstVisibleBlock() while block.isValid(): if block.blockNumber() in self.lineError: block.blockFormat().setBackground(QBrush(self.errorColor)) block.charFormat().setBackground(QBrush(self.errorColor)) block= block.next() Have you any idea?...

PyQt, Python 3: Lambda slot assigning signal argument to a variable?

python,python-3.x,pyqt
Assuming the following PyQt signal: value_changed = pyqtSignal(value) Is there a way to write a lambda slot that would assign the value provided by the signal to a certain variable, as in this (obviously illegal) example: object1.value_changed.connect(lambda val: var1=val) object2.value_changed.connect(lambda val: var2=val) ... What would be the most concise way...

How to put a child window inside a main window(PyQt)

qt,pyqt,parent,childwindow
I looked here in stackoverflow and google for some days for something like my case, but all the examples I found did not work. What I want is to have my parent window with the menu, and then call other child windows from that menu and execute/show them inside the...

Layout management on PyQt4 Docks

api,pyqt,pyqt4,docking
I am a total GUI n00b developing an application in PyQt4. The application is designed for a lab bench, in which it will first search for equipment, and then populate the main window with docked windows, one for each piece of equipment it finds. The interface for each piece of...

How to import resource file in PyQt and build with pyinstaller?

python,pyqt,pyinstaller
First of all, I have use Qt Designer to turn a picture into a .qrc file, Then I use pyrcc4 to turn this .qrc file into a .py resource. pyrcc4 qrcfile.qrc -o pyfile.py then import this .py file in my .py file. but after build with pyinstaller this resouce file...

PyQt5 QTextEdit auto completion

python-3.x,autocomplete,pyqt,qtextedit,pyqt5
Looking for a way to have an auto completion with a QTextEdit and QCompleter. I have read that it is possible but didn't find any example... I'm using python3.4 and PyQt5 I'm looking for a very basic example thanks for any help...

QTableView / QTableWidget: Stretch Last Column using Qt Designer

pyqt,pyqt4,qt-designer,pyqt5
I am trying to stretch the last header of my QTableView / QTableWidget in PyQt. Multiple questions have been asked about this topic already by hard coding the value into the file such as: Qt table last column not stretching to fill in parent How to stretch QTableView last column...

PyQT4 Datetime widget

python,pyqt,pyqt4
I'm using PyQt4 to make a Application and on the window their is a datetime-label( live updating). I Wan't to put this label into a Hboxlayout, together with two other QLabels. This code is used: import sys,os from PyQt4 import QtGui,QtCore from label_datetime import * class ApplicationWindow(QtGui.QMainWindow): def __init__(self): QtGui.QMainWindow.__init__(self)...

Uppercase input in QLineEdit python way

python,pyqt,qlineedit
I had drawn up an UI using the QT Designer but found out that there are no parameters for me to set QLineEdit inputs to be uppercase. After doing some online searching, I have only seen a very few handful of results that cater to my needs, however all are...

PyQt SimpleHTTPServer: GUI freezes on starting server

python,multithreading,pyqt,multiprocessing,simplehttpserver
I am trying to create a simple desktop app using PyQt that runs a SimpleHTTPServer on clicking a start server button. I have tried using threads(both python threads and Qthread) and understand that this is not possible as it runs into issues with the GIL. Here's the code def btn_startserver_clicked(self):...

What's the difference between @pyqtSignature() and @pyqtSlot() pyqt decorators

python,qt,pyqt,pyqt4
I was trying to write a slot that connects to different pyqt signals. What I still can't wrap my head around is the difference between the two decorators @pyqtSignature() and @pyqtSlot(). Example to connect to pyqt clicked signal of QPushButton which is inherited from QAbstractButton, I used the following syntax...

How can I make link on web page in window using pyqt4?

python,qt,hyperlink,pyqt,pyqt4
I have a problem. Can I make a link on the web page in the window and when the user clicks on it, the web page will be open in the browser. For example: import sys from PyQt4 import QtGui, QtCore app = QtGui.QApplication(sys.argv) main = QtGui.QWidget() main.setGeometry(200, 200, 200,...

Displaying pyqtgraph and pyqt widgets on web

python,django,pyqt,saas,pyqtgraph
Is there a way to take existing python pyqtgraph and pyqt application and have it display on a web page to implement software as a service? I suspect that there has to be a supporting web framework like Django in between, but I am not sure how this is done....

How to call a function in pyside MainWindow from another python script

python,qt,pyqt,pyside,mainwindow
This is my main.py I have a function called loadShot that I want to call from another class MainWindow(QMainWindow): # Main Window UI def __init__(self, parent=None): QMainWindow.__init__(self, parent) loadUi(os.path.join(SCRIPT_DIRECTORY, 'mainwindow.ui'), self) self.connectInterface() # Connect signals def connectInterface(self): self.scene_Line.textChanged.connect(self.shotName) self.activeProjcet_Line.textChanged.connect(self.shotName) self.character_Line.textChanged.connect(self.shotName)...

Qt Widget with slider

python,qt,pyqt
I'm writing GUI application using PyQt4 and I need to create widgets and dialog windows which can be slided vertically. After clicking "Add new widgets" button (and moving it down) I create dynamically new small widgets (containing 2 textEdit objects). I want to avoid situation when window's height will be...

QFileSystemWatcher error handling with PySide/PyQt - Python 3.x

python,qt,pyqt,pyside,qfilesystemwatcher
My program utilises Qt's QFileSystemWatcher function to monitor a network directory (not on the local machine itself) for changes, and then run a script when a change is found. This function performs as required for the most part. The program is designed to run 24/7, which has raised some issues...

PyQt4: set a default font?

fonts,pyqt
I'm adjusting a GUI written in PyQt4, and I'd like to change every last bit of text that appears in it to a different font than what PyQt uses by default. I've been doing this by calling widget.setStyleSheet("font-family: DesiredFont;") on every widget with text in it. This is very cumbersome....

Why aren't my QRadioButtons 'exclusive' after being added to separate QButtonGroups?

python,qt,pyqt,pyside,qradiobutton
from PySide import QtCore from PySide import QtGui class UI(QtGui.QDialog): def __init__(self): super(UI,self).__init__() self.setWindowTitle('Test UI 2000') self.create_layout() def create_layout(self): mainLayout = QtGui.QVBoxLayout() self.setLayout(mainLayout) fruitLabel = QtGui.QLabel('Fruit') junkLabel = QtGui.QLabel('Junk') buttonGroup1 = QtGui.QButtonGroup() radioButtonA = QtGui.QRadioButton('Apple') radioButtonB = QtGui.QRadioButton('Pear') buttonGroup1.addButton(radioButtonA) buttonGroup1.addButton(radioButtonB) buttonGroup2 =...

Difficulties with re-using a variable

python,user-interface,pyqt
here is a part of my code : class projet(object): def nameCouche(self): valLissage = float(ui.valLissage.displayText()) return (valLissage) valCouche = nameCouche() # asks for a positional argument but 'self' doesnt work def choixTraitement(self): ui.okLissage.clicked.connect(p.goLissage) def goLissage(self, valCouche): if ui.chkboxLissage.isChecked(): print(valCouche) # result is False os.system(r'"C:\Program Files\FME\fme.exe" D:\Stelios\..... --MAX_NUM_POINTS {0}'.format(valCouche)) So I...

PyQt5: QTimer out of sync after minimizing window (OSX)

python,osx,pyqt,pyqt5
I have a problem with the usage of the pyqt5 QTimer class and OSX. If following simple application gets minimized by clicking on the yellow button on the top left of the window, the application moves as expected to the bottom right of the dock bar and the timer increases...

PyQT: draw a QPainterPath() in rect?

python,qt,pyqt,pen
With Qt, if you use QPainter.drawText() you can pass a string of characters you want to draw and coordinates of the bounding rect as argument. However when drawing a path with QPainter.drawPath() you can't just specify a bounding rect or coordinates the path should fit in. Is there a...

How to undo an edit of a QListWidgetItem in PySide/PyQt?

qt,pyqt,pyside
Short version How do you implement undo functionality for edits made on QListWidgetItems in PySide/PyQt? Hint from a Qt tutorial? The following tutorial written for Qt users (c++) likely has the answer, but I am not a c++ person, so get a bit lost: Using Undo/Redo with Item Views Longer...

Python - matplotlib - PyQT: plot to QPixmap

python,matplotlib,plot,pyqt
I want to visualise matplotlibs colormaps (similar to http://matplotlib.org/examples/color/colormaps_reference.html) and use it as QPixmaps in PyQt widgets. The idea is to create the plots in matplotlib without actually showing it (or saving it to a file) and convert it to a QPixmap. The solution offered here (Python - matplotlib -...

Wrong widget order using vbox layout PyQt

python,widget,pyqt
I am trying to put a QLabel widget on top of (ie before) a QLineEdit widget edit. But it keeps appearing after the QLineEdit widget. My code, class CentralWidget(QtGui.QWidget): def __init__(self, parent=None): super(CentralWidget, self).__init__(parent) # set layouts self.layout = QtGui.QVBoxLayout(self) # Flags self.randFlag = False self.sphereFlag = False self.waterFlag =...

Highlight item with mouse hover in QTreeView?

qt,pyqt,pyqt4,pyside
I have a QStandardItemModel that I am displaying as a QTreeView with multiple columns (if it matters, I am showing the tree as the central widget of a QMainWindow). I would like to highlight items when the mouse hovers over them. Related pages How to catch mouse over event of...

PyQt5: one signal comes instead of two as per documentation

python,pyqt,python-3.3,signals-slots,pyqt5
I have been reading the section "Connecting Slots By Name" on this PyQt5 documentation page which basically describes new signals and slots functionality. This piece caught my eye: For example the QtGui.QSpinBox class has the following signals: void valueChanged(int i); void valueChanged(const QString &text); When the value of the spin...

PyQt ToolTip for QTreeView

pyqt,tooltip,qtreeview
Please axplain how to enable and show a tooltip for each item in QTreeView. I found a sample of code class TreeModel(QAbstractItemModel) but due to my beginner's level I can't understand how to apply it to my needs. Data for tooltip should be taken from value of key "note" in...

PyQt, QComboBox with QStringModel cause QObject::startTimer: QTimer can only be used with threads started with QThread

python,qt,pyqt,qcombobox
below is runnable example for PyQt4, I using below code and got very strange issue like this QObject::startTimer: QTimer can only be used with threads started with QThread after closed the window: combo = ExtendedComboBox() # combo.addItems(string_list) combo.setModel(QStringListModel(string_list)) Once I changed to below codes, everything is working well: combo =...

Is a mutex really necessary in this piece of code?

python,pyqt,mutex
The code below shows a class which I use for PyQt threading functionality. In my main program I instantiate and start this thread (i.e. I use PyQt's moveToThread, and countdown is the run method.). While the thread is running I frequently call the reset method. I'm not sure if the...

Put a QLineEdit() into a QTreeWidgetItem()

python,python-3.x,pyqt,pyqt5
Is it possible to put a QLineEdit() into a QTreeWidgetItem() in order to modify the text of the QTreeWidgetItem ? Here is my code def addItemsToTree(self, parent, text, checkable=False, expanded=True): self.item = QTreeWidgetItem(parent, [text]) if checkable: self.item.setCheckState(0, Qt.Unchecked) else: self.item.setFlags(self.item.flags() & ~Qt.ItemIsUserCheckable) self.item.setExpanded(expanded) min = QLineEdit() max = QLineEdit() self.addChildTree(self.item,...

PyQT Qtabwidget hide and close certain tab

python,tabs,pyqt
Is it possible to hide and close a certain tab in Qtabwidget? I have 5 tabs, two of them are plots and generated while using my software. First I want to hide the two plots in the beginning and second I want to make them closable after there were generated....

Python crashes using pyqt, setPixmap and QLabel

python,python-2.7,pyqt
I'm using this python code on a windows 7 64-bit machine, which simply displays a randomly generated black and white image. If I make the image larger than 511x511 pixels, my python 2.7 console crashes. It works fine on my Mac though. Any ideas? import sys from PyQt4 import QtGui,...

QGraphicsView vector edit: update path when moving node – properly?

python,qt,pyqt,vector-graphics,qgraphicsview
I am creating a vector editing window. I add elements to a QGraphicsScene and display it. I am yet writing code so that when moving a node, it moves the underlying path as well. But how do I move the two joints of the path that lead to the point...

Accessing dynamically added widgets (pyqt)

python,pyqt,qtgui
I want add text into a text box which I've added using a push button based on the accepted answer for this question : Dynamically adding and removing widgets in pyqt My problem however is that I cannot access the text boxes I've added. This post tells me that I...

How to save a treeview as pdf in PySide/PyQt?

qt,pdf,pyqt,pyside
Short version I have a simple QTreeView embedded in a widget: I want to save the tree as a PDF so users can print it. How can I do this? Details I want to save the tree as a PDF when I click the 'print' button. Based on this question,...

how to get the default size of a window in pyqt4

python,qt,pyqt
When I create a QMainWindow without explicitly specifying its dimensions, PyQt will give it a -let's say- "standard size" which is not the minimum that the window can get. Can I set this size at will in any way? My goal is to get this "standard size" according to the...

pyqt gui locked when calling cython function from QThread.run

python,user-interface,pyqt,cython,qthread
In PyQt4 I want to execute code with no lock gui. I use QThread and emit signal for gui update. But if i call cython function in QThread.run gui will be locked. class Runner(QtCore.QThread): iter = QtCore.pyqtSignal(int) def __init__(self): QtCore.QThread.__init__(self) def do_something(self): beg = time.time() s = 0.0 while time.time()...

PyQt QVariant with dictionary

python,pyqt
If you execute this code in python: from PyQt4 import uic, QtCore, QtGui qvdict = QtCore.QVariant(dict(name='a')) print qvdict.toPyObject() qvtuple = QtCore.QVariant(('name','a')) print qvtuple.toPyObject()) The result is: {PyQt4.QtCore.QString(u'name'): PyQt4.QtCore.QString(u'a')} ('name', 'a') As you can see keys and string values in qvdict are converted to QString but not for the qvtuble. Is...

PyQt: QDataWidgetMapper mapping for custom property

python,pyqt,pyqt5,qabstractitemmodel
In PyQt I want to use a QAbstractItemModel and QDataWidgetMapper to map widgets to the model data. For QLineEdit it works fine, but I want to have a mapping between a QButtonGroup (filled with several QRadioButton) and the model. Therefore I subclassed QGroupBox and added a custom property selectedOption: class...

QT Event filter for holding mouse button down

python,qt,pyqt
How would I modify the filter to fire when the user presses and holds rather than just presses? I have something working, but it's not contained entirely in a filter, and it gets messy. I can't figure out how to determine if the user is holding the button for some...

PyQt4 - How to shrink the layout on Mac OSX?

python,osx,qt,layout,pyqt
For the same PyQt4 code, the layout looks quite equivalent on Linux and Windows. But with MacOSX, we see that : the elements seems to take a little more space (mostly bt_bookmark which doesn't shrink to the expected size) a lot of space is used between the elements (that's the...

How do I compile QScintilla and Eric6 on Linux?

python,linux,compilation,pyqt,qscintilla
First I install QScintilla by following steps: 1: cd Qt4Qt5 qmake qscintilla.pro sudo make make install 2: cd ../designer-Qt4Qt5 qmake designer.pro sudo make sudo make install 3: cd ../Python python3 configure.py --pyqt=PyQt5 sudo make And here I met the problem : QAbstractScrollArea: No such file or directory and problem: qprinter.h:...

How to access a variable of a class created within another class, from outside either class

python,class,pyqt
I have a class whose attributes I need to access. The problem comes with the fact that the instance of this class is instantiated within another class. Here is the class whose variable I wish to access (there is more to it, but this shows you how the class is...

How to get value of QtComboBox?

python,qt,pyqt,qt-designer
I am creating a QGIS plugin using a QGIS plugin builder template. def __init__(self, iface): #some code self.dlg = QtGui.QDialog(); main_layout = QtGui.QVBoxLayout() city = QtGui.QComboBox() city.addItem("Tucson") city.addItem("Austin") city_label = QtGui.QLabel("City", city) buttons = QDialogButtonBox( QDialogButtonBox.Ok | QDialogButtonBox.Cancel, Qt.Horizontal, self.dlg) buttons.accepted.connect(self.dlg.accept) buttons.rejected.connect(self.dlg.reject) main_layout.addWidget(city) self.dlg.setLayout(main_layout) def run(self):...

Casting a QObject subclass instance

python,pyqt,pyqt4
I have a QPixmap subclass with additional class method make: class Screenshot(QtGui.QPixmap): @classmethod def make(cls): desktop_widget = QtGui.QApplication.desktop() image = cls.grabWindow( desktop_widget.winId(), rect.x(), rect.y(), rect.width(), rect.height()) import ipdb; ipdb.set_trace() image.save() return image When I call Screenshot.make() the correct class cls is passed, but the instance created via cls.grabWindow is not...

How use PyQt without GUI?

python,pyqt,pyqt4
I want create python server application using PyQt4 without GUI ( signal/slots, threads, process and other core patterns ). How i can create this?

Using Py2app with a GUI from QT Creator

python,qt,user-interface,pyqt,py2app
I created a GUI in QT Creatro and stored this as a *.ui file. Using PyQT I made a GUI that works fine when it is launched as $ python pyapp.py In order to build this app into something that can be executed by double clicking on it, I used...

How to implement a Checkbox Group in PyQtGraph

python,pyqt
I am using pyqtgraph in python for some graphing capability. I've added a few checkboxes: check1 = QtGui.QCheckBox(win) check2 = QtGui.QCheckBox(win) check3 = QtGui.QCheckBox(win) check4 = QtGui.QCheckBox(win) check1.setText("Checkbox 1") check2.setText("Checkbox 2") check3.setText("Checkbox 3") check4.setText("Checkbox 4") gridLayout.addWidget(check1, 1, 2, 1, 1) gridLayout.addWidget(check2, 1, 4, 1, 1) gridLayout.addWidget(check3, 1, 6, 1, 1)...

How can i create a searchbar in pyqt

python,mysql,user-interface,pyqt
I'm making a glossary of Keywords. I've considered putting all the terms in a big label. But that's not efficient or nice to look at. How can i make a form with a search-bar which displays all the terms but allows you using the search-bar to filter it depending what...

Add custom attribute to QCheckBox widget

pyqt,attr,qwidget
I have (I think) a simple question but haven't had much luck trying to find an answer. Really new to pyqt! I am dynamically adding a number of QtGui.QCheckBox() widgets to a gridLayout based on a number of factors. My question is, how can I add a custom attr to...

PyQt GUI order of operations

python,python-2.7,user-interface,pyqt,pyqt4
I have a following problem: upon pressing a button in PyQt made GUI I have to do two actions: Immediately update a QTextBrowser Run a method that will wait for some time and enable some buttons after. What I get is that 1 and 2 are done at the same...

PyQT4: Adding combobox in Qtableview

combobox,pyqt,qt4,tableview
I am new to PyQT. I am interested to add a combobox to the each row of tableView. Is it possible in PyQT 4? I know, it is possible in QT5, but not sure about PyQT. Thank you in advance for help....