QLayout: Attempting to add QLayout “” to QWidget “”, which already has a layout

When you assign a widget as the parent of a QLayout by passing it into the constructor, the layout is automatically set as the layout for that widget. In your code you are not only doing this, but explicitly calling setlayout(). This is no problem when when the widget passed is the same. If they … Read more

Are there default icons in PyQt/PySide?

What you need is Pyside QIcon.fromTheme function. Basicaly it creates QIcon object with needed icon from current system theme. Usage: undoicon = QIcon.fromTheme(“edit-undo”) “edit undo” – name of the icon “type”https://stackoverflow.com/”function” can be found here This works on X11 systems, for MacOSX and Windows check QIcon documentation QIcon.fromTheme Edit Inserting this from the website, since … Read more

Loading QtDesigner’s .ui files in PySide

For the complete noobs at PySide and .ui files, here is a complete example: from PySide import QtCore, QtGui, QtUiTools def loadUiWidget(uifilename, parent=None): loader = QtUiTools.QUiLoader() uifile = QtCore.QFile(uifilename) uifile.open(QtCore.QFile.ReadOnly) ui = loader.load(uifile, parent) uifile.close() return ui if __name__ == “__main__”: import sys app = QtGui.QApplication(sys.argv) MainWindow = loadUiWidget(“:/forms/myform.ui”) MainWindow.show() sys.exit(app.exec_())

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

If you’re coming here from Google and not having luck with the accepted answer, that’s because you’re missing the other secret invocation: QScrollArea::setWidget. You must create and explicitly identify a single widget which is to be scrolled. It’s not enough to just add the item as a child! Adding multiple items directly to the ScrollArea … Read more

How to set QComboBox to item from item’s text in PyQt/PySide

Yes, there is QComboBox.findText, which will return the index of the matched item (or -1, if there isn’t one). By default, the search does exact, case-sensitive matching, but you can tweak the behaviour by passing some match-flags as the second argument. For example, to do case-insensitive matching: index = combo.findText(text, QtCore.Qt.MatchFixedString) if index >= 0: … Read more

PySide / PyQt detect if user trying to close window

Override the closeEvent method of QWidget in your main window. For example: class MainWindow(QWidget): # or QMainWindow … def closeEvent(self, event): # do stuff if can_exit: event.accept() # let the window close else: event.ignore() Another possibility is to use the QApplication‘s aboutToQuit signal like this: app = QApplication(sys.argv) app.aboutToQuit.connect(myExitHandler) # myExitHandler is a callable

PySide – PyQt : How to make set QTableWidget column width as proportion of the available space?

This can be solved by setting the resize-mode for each column. The first section must stretch to take up the available space, whilst the last two sections just resize to their contents: PyQt5: header = self.table.horizontalHeader() header.setSectionResizeMode(0, QHeaderView.Stretch) header.setSectionResizeMode(1, QHeaderView.ResizeToContents) header.setSectionResizeMode(2, QHeaderView.ResizeToContents) PyQt6/PyQt5: header = self.table.horizontalHeader() header.setSectionResizeMode(0, QHeaderView.ResizeMode.Stretch) header.setSectionResizeMode(1, QHeaderView.ResizeMode.ResizeToContents) header.setSectionResizeMode(2, QHeaderView.ResizeMode.ResizeToContents) PyQt4: header = … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)