How to create collapsible box in PyQt

Using as base the logic that is implemented in the solution of @xsquared modifying certain parts we obtain the following: PyQt4 version from PyQt4 import QtCore, QtGui class CollapsibleBox(QtGui.QWidget): def __init__(self, title=””, parent=None): super(CollapsibleBox, self).__init__(parent) self.toggle_button = QtGui.QToolButton( text=title, checkable=True, checked=False ) self.toggle_button.setStyleSheet(“QToolButton { border: none; }”) self.toggle_button.setToolButtonStyle( QtCore.Qt.ToolButtonTextBesideIcon ) self.toggle_button.setArrowType(QtCore.Qt.RightArrow) self.toggle_button.pressed.connect(self.on_pressed) self.toggle_animation = QtCore.QParallelAnimationGroup(self) … Read more

QtCore.QObject.connect in a loop only affects the last instance

Put the loop variable in a default argument, like this: lambda state, instance=instance: findInstance.projectsInstance.myslot( “TWCH”, findInstance, instance.text(), instance.checkState(), instance) This will give each lambda its own local copy of the instance variable. EDIT Here’s a simple script that demonstrates how to use default lambda arguments: from PyQt4 import QtGui class Window(QtGui.QWidget): def __init__(self): QtGui.QWidget.__init__(self) layout … Read more

How to add static(html, css, js, etc) files in pyinstaller to create standalone exe file?

From your question you can presume that the structure of your project is as follows: ├── index.html ├── jquery.js ├── main.py ├── my_custom.js └── styles.css For your case there are 2 options: using –add-data import os import sys from PyQt5 import QtCore, QtWidgets, QtWebEngineWidgets def resource_path(relative_path): “”” Get absolute path to resource, works for dev … Read more

Is there a difference between QFileDialog strings in PyQt4 and PyQt5?

The getOpenFileName function in PyQt4 returns a string that is the name of the selected file, and if none is selected then it returns an empty string. filename = QFileDialog.getOpenFileName(self, “Open Template”, “c:\\”, “Templates (*.xml);;All Files (*.*)”) However in PyQt5 this returns a tuple of 2 elements where the first one is a string that … Read more

PyQT: how to open new window

Here I’m using the show method. Here is a working example (derived from yours): #!/usr/bin/env python # -*- coding: utf-8 -*- from PyQt4 import QtGui, QtCore import sys class Second(QtGui.QMainWindow): def __init__(self, parent=None): super(Second, self).__init__(parent) class First(QtGui.QMainWindow): def __init__(self, parent=None): super(First, self).__init__(parent) self.pushButton = QtGui.QPushButton(“click me”) self.setCentralWidget(self.pushButton) self.pushButton.clicked.connect(self.on_pushButton_clicked) self.dialog = Second(self) def on_pushButton_clicked(self): self.dialog.show() def … Read more

How to display a Pandas data frame with PyQt5/PySide2

In the case of QTableView the data must be provided through a model since it implements the MVC (Model-View-Controller) paradigm, in the case of pandas there is no default model but we can create a custom as shown in the following part: class PandasModel(QtCore.QAbstractTableModel): def __init__(self, df = pd.DataFrame(), parent=None): QtCore.QAbstractTableModel.__init__(self, parent=parent) self._df = df.copy() … Read more