PyQt: Always on top

Pass the QMainWindow the WindowStaysOnTopHint window flag (or use setWindowFlags). As in the name, this is a hint to the windowing manager (not a hard guarantee). Simplest possible example: import sys from PyQt4 import QtGui, QtCore class mymainwindow(QtGui.QMainWindow): def __init__(self): QtGui.QMainWindow.__init__(self, None, QtCore.Qt.WindowStaysOnTopHint) app = QtGui.QApplication(sys.argv) mywindow = mymainwindow() mywindow.show() app.exec_()

How to Copy – Paste Multiple Items form QTableView created by QStandardItemModel to a text/excel file?

The difficulty here is that the selected cells in the table may be non-contiguous and not in any particular order. So the task is to calculate the smallest rectangle that will include all the selected cells, and then create a data structure from that which is suitable for passing to a csv writer. Below is … Read more

How to drop a custom QStandardItem into a QListView

It looks like you want setItemPrototype. This provides an item factory for the model, so that it will implicitly use your custom class whenever necessary. All you need to do is reimplement clone() in your item class: class MyItem(QtGui.QStandardItem): ”’This is the item I’d like to drop into the view”’ def __init__(self, parent=None): super(MyItem, self).__init__(parent) … Read more

How to change the color of the axis, ticks and labels

As a quick example (using a slightly cleaner method than the potentially duplicate question): import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot(111) ax.plot(range(10)) ax.set_xlabel(‘X-axis’) ax.set_ylabel(‘Y-axis’) ax.spines[‘bottom’].set_color(‘red’) ax.spines[‘top’].set_color(‘red’) ax.xaxis.label.set_color(‘red’) ax.tick_params(axis=”x”, colors=”red”) plt.show() Alternatively [t.set_color(‘red’) for t in ax.xaxis.get_ticklines()] [t.set_color(‘red’) for t in ax.xaxis.get_ticklabels()]

qfiledialog – Filtering Folders?

You can try setting a proxy model for your file dialog: QFileDialog::setProxyModel. In the proxy model class override the filterAcceptsRow method and return false for folders which you don’t want to be shown. Below is an example of how proxy model can look like; it’c c++, let me know if there are any problems converting … Read more

Pygame not returning events while embedded in PyQt

A functional code implementation: import time import contextlib from PySide6.QtCore import QObject, Signal, Qt, QThread from PySide6.QtGui import QImage, QPixmap from PySide6.QtWidgets import QMainWindow, QLabel, QWidget, QVBoxLayout, QApplication with contextlib.redirect_stdout(None): import pygame DISPLAY_WIDTH = 800 DISPLAY_HEIGHT = 600 class PygameWorker(QObject): send_image = Signal(QImage) def run(self): # Initialise screen pygame.init() screen = pygame.display.set_mode((DISPLAY_WIDTH, DISPLAY_HEIGHT), pygame.OPENGL) # … Read more

Sorting in pyqt tablewidget

Its sorting alpha-numerically (so, in terms of strings, ‘1’, ’10’, ’11’, ’12’, ‘2’, ’20’, ’21’, ’22’, ‘3’, ‘4’ etc. is the proper sort order. It appears that for a QTableWidgetItem, if you use the setData(Qt.EditRole, value) method, the sort order will work. Depending on your version of Qt (I assume) you may have to overload … Read more

PyQt: How to hide QMainWindow

Make the first window a parent of the second window: class Dialog_02(QtGui.QMainWindow): def __init__(self, parent): super(Dialog_02, self).__init__(parent) # ensure this window gets garbage-collected when closed self.setAttribute(QtCore.Qt.WA_DeleteOnClose) … def closeAndReturn(self): self.close() self.parent().show() class Dialog_01(QtGui.QMainWindow): … def callAnotherQMainWindow(self): self.hide() self.dialog_02 = Dialog_02(self) self.dialog_02.show() If you want the same dialog to be shown each time, do something like: … Read more