FAQ Database Discussion Community


PyQt5 button to run function and update LCD

python,user-interface,python-3.x,pyqt5
I am getting started with creating GUI's in PyQt5 with Python 3. At the click of the button I want to run the "randomint" function and display the returned integer to the QLCDNumber named "lcd". Here's my code: import sys from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QPushButton, QLCDNumber from random...

Scaling and printing PyQt

python,printing,pyqt,pyqt5
I'm attempting to print to paper a main window along with its widgets. Ideally it should fit the page. I've attempted the following code but to no avail! Any body know how to? def printViewCustomer(self): printer=QtPrintSupport.QPrinter() dialog=QtPrintSupport.QPrintDialog(printer,self) if (dialog.exec_()!=QtWidgets.QDialog.Accepted): return printWidget=self.mainViewWidget painter=QtGui.QPainter(printer) painter.begin(printer) print(printer.paperRect().x()) XScale=(printer.pageRect().width()/ (printWidget.width()))...

cmd/DOS window opens with GUI created with py2exe

python,user-interface,cmd,py2exe,pyqt5
I have created a GUI using PyQt5. The aim of the GUI is to pass some input data (images, shapefiles etc) and to use them in softwares (GIS mostly). To launch the GIS I use the subprocess.Popen command line. I have used py2exe to create my app and my problem...

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....

Can't make PyQt5 Gui work, python3

python-3.4,pyqt5
i've made several guis with Qt Designer and then with PyQt5 i converted the .ui to .py, however, whenever i run this code on python3 nothing happens, no gui, no errors, nothing, i'm quite new to python and i have no idea why this is happening. -- coding: utf-8 --...

Matplotlib in PyQt5: How to remove the small space along the edge

python,matplotlib,pyqt,pyqt5
I have a matplotlib.pyplot object inside a QVBoxLayout in PyQt5 widget. There are small spaces along the edge which is really annoying. How do I remove it? See the screensnap below. I already tried setlayoutSpacing(0), which have no effect. Here is the breviate code (Cutout many data processing codes): class...

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 - 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: 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...

Preventing jedi to complete everything after space

python-3.x,pyqt5,python-jedi
I am trying to use jedi to complete python code inside a PyQt application, using QCompleter and QStringListModel to store the possible completion. Here's a simple working demo: #!/usr/bin/env python3 from PyQt5.QtCore import * from PyQt5.QtWidgets import * import jedi import sys class JediEdit(QLineEdit): def __init__(self, parent=None): super().__init__(parent) self._model =...

remove padding/margin from QTabBar in QLayout

python,qt,pyqt4,pyqt5,qss
I have an application where I want the QTabBar to be in a separate VBoxLayout from the QTabWidget area. It sort of works using the code below but I'm having styling problems. Before I separated the QTabBar from the QTabWidget I didn't have any problems but now I can't figure...

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...

Animating a rectangle in PyQT5: Why is QtCore not defined?

python,pyqt5
I am trying to animate a rectangle in PyQT by creating an animation loop. I have done this in TKinter using the window.after() method and am trying to do the same thing in PyQt5 using QtCore.QTimer.singleShot(), however, when I run the code it says that QtCore is not defined yet...

pyqt5: why the mimeData().text() returns nothing?

python-3.x,drag-and-drop,pyqt5
learning PyQt5 recently, I've tried to drag a QPushButton learning this tutorial Drag & drop a button widget, and made some improvements to place the button more accurate, so I add mime = e.mimeData().text() x, y = mime.split(',') according to @Avaris for this question, but I found e.mimeData().text() returned nothing...

QT Designer how to assign 2 hotkeys to a QPushButton (python3)

python-3.x,keyboard-shortcuts,qt-designer,pyqt5,qpushbutton
I created a simple GUI and assigned "Enter" to QPushButton ("Begin"). This is the line for it: self.Begin.setShortcut(_translate("Form", "Enter")) Evrything works perfectly, BUT how to assign 2 variants of hotkey for the same button? I want the button to react to 2 hotkeys: Enter and Return (Usual "Big Enter" and...

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...

QLineEdit being deleted after a couple of sceens

python,pyqt5
I'm using a QLineEdit and then needing to refer to it after 2 screens in PyQt. However I consistently keep getting this error when I refer to it Traceback (most recent call last): File "[filename]", line 227, in passwordmissing2ndscreenverify P1=self.entrypasswordmissingscreen1.text() RuntimeError: wrapped C/C++ object of type QLineEdit has been deleted...

How to close Pyqt5 program from QML?

qt,python-3.x,qml,signals-slots,pyqt5
I started a project in Qt Creator initially with a C++ backend, but then switched it to use PyQt5. I have a main.qml, where when I press a button called Exit, I call Qt.quit(). However, I get a General Message stating: Signal QQmlEngine::quit() emitted, but no receivers connected to handle...

QWidget cannot display on QMainWindow instance PyQt5

python-3.x,pyqt5
I am learning PyQt5 now and tried to do something little on my own. I have made a very basic custom toolbox, which has just 6 QPushButtons buttons on it, which inherits from QWidget class. My problem is that I can't display my toolbox on my QMainWidow instance. Let me...

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...

How to center an icon in QStandardItemModel?

qt,pyqt4,pyqt5
def data(self, index, role): if role == Qt.DecorationRole: if index.column() == 0: return QApplication.style().standardIcon(QStyle.SP_DialogYesButton if self.item(index.row()).valid else QStyle.SP_DialogNoButton) elif role == Qt.TextAlignmentRole: if index.column() == 0: return QVariant(Qt.AlignCenter | Qt.AlignVCenter) The icons are displayed well but they are not centered....

sqlite3 table into QTableWidget, sqlite3, PyQt5

python-3.x,sqlite3,pyqt5
I have created a program that manages tables in a database, now i'm trying to make a gui for it, and i figured the easiest way would be to do it with Qt Designer and then convert it to python with PyQt5, and so i did it, i know how...

Pyqt5 TypeError: can't use a string pattern on a bytes-like object

python,regex,pyqt5
I need to write a program having a GUI to input a File - shtech1.txt Then need to open the file and extract lines between show vlan and show and write to another file - shvlan1.txt Below is my program and I am getting error TypeError: can't use a string...

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...

Python GUI not capturing zeromq message

python,user-interface,zeromq,pyqt5
I have a small program where I am not receiving a response from the server. This is using python 3.4 and latest zeromq and pyqt5 on Ubuntu 14.04. The client GUI sends a message to the server which gets it and responds but the client does not see the...

Running python code exported from qt creator and converted to python using pyqt5

qt,python-3.x,qt-creator,pyqt5
I recently encountered this error after attempting to run my python script. In short, I simply don't understand how I've fed three arguments. I've included what I considered to be the most relevant snippets of code. Help is very appreciated. Thank you. Traceback (most recent call last): File "DESeq_rpkm_gui.py", line...

Fresh Qt installation does not run Qt projects, including many of Qt Example projects, says “shader program not linked”

qt,opengl,shader,pyqt5
Yesterday I installed Qt 5.4 on my windows 7 PC. But I can not build and run any Qt project including those given in Examples section on the Welcome page of Qt Creator 3.3 except for a few. Also, I can’t run any qml file either using this command from...

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...

Where did file downloaded with PyQt5 network access manager go? And how do I save it?

qt,qt5,pyqt5,qnetworkaccessmanager,qnetworkreply
Without specifying file to save, I created this: def start_download(self): self.reply = self.manager.get(QNetworkRequest(QUrl(self.url_edit.text()))) self.reply.downloadProgress.connect(self.download_progress) self.label.setText(self.url_edit.text()) def download_progress(self, received, total): print(received, type(received)) The last function I mentioned did write received byte. So, the is downloaded. Where did it go without I specified path to save? And How can I save it?...

Python3 can't find and import PyQt5

osx,python-3.x,pyqt5
I installed PyQt5 with brew and it appears to end up the install process properly. $ brew install pyqt5 --with-python3 The problem is that I can't get it to import: Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 23 2015, 02:52:03) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright",...

Pop up dialog from one button on the main window, PyQt5

pyqt5
i have created a main window with a table, and two buttons, and i also have created a dialog window, with a label, a line edit for user input, and two buttons.. I would like the dialog to pop up once one button in the main window is pressed, take...

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...