Skip to content

Qt for Python

For discussion and questions about Qt for Python (PySide & Shiboken)

3.3k Topics 14.6k Posts
  • How to track user inactivity

    Unsolved
    4
    0 Votes
    4 Posts
    611 Views
    JonBJ
    @Mikeeeeee So you will have to write code to detect exactly those things you want to monitor. Probably through an event filter. And if none arrive the user is inactive, in those terms. I don't know what else to say.
  • save changes done to items in a treewidget

    Unsolved
    2
    0 Votes
    2 Posts
    300 Views
    JonBJ
    @iwrwrc Changes made from a QTreeWidget should go through to the underlying model and be saved there. They will persist across tab changes, unless you have something wrong in your code.
  • Display images(or image streams) in QML from Python

    Unsolved
    6
    0 Votes
    6 Posts
    3k Views
    S
    Can you pass a singleton into a QML register Type? or rather import a singleton so that this python file can access the continuously changing data from another python file or class instance. For example "from main import myTestClasse" so far the data is not updating to match the singleton myTestClasse and was wondering if there is an extra step that needs to be taken? From the example listed above with modifications :... """ import numpy as np import threading #from PySide6 import Qt import cv2 """ from PySide6 import QtCore, QtGui, QtQml from PySide6.QtCore import QObject, Signal, Slot, Property from main import myTestClasse def max_rgb_filter(image): # split the image into its BGR components (B, G, R) = cv2.split(image) # find the maximum pixel intensity values for each # (x, y)-coordinate,, then set all pixel values less # than M to zero M = np.maximum(np.maximum(R, G), B) R[R < M] = 0 G[G < M] = 0 B[B < M] = 0 # merge the channels back together and return the image return cv2.merge([B, G, R]) gray_color_table = [QtGui.qRgb(i, i, i) for i in range(256)] class CVCapture(QtCore.QObject): #once the camera caputre is started from completion of the QML , send signal that the image capture has started started = Signal() imageReady = Signal() indexChanged = Signal() def __init__(self,parent=None): super(CVCapture, self).__init__(parent) self._image = QtGui.QImage() self._index = 0 #self.image_handler = image_handler #self.m_videoCapture = cv2.VideoCapture() self.m_timer = QtCore.QBasicTimer() #self.m_filters = [] self.m_busy = False #self.testImage = None #self.frame = None @Slot() @Slot(int) def start(self, *args): print('start the image display') if args: self.setIndex(args[0]) self.m_timer.start(50, self) self.started.emit() @Slot() def stop(self): self.m_timer.stop() def timerEvent(self, e): #print(f'image handler data is {image_handler.oneSecondCounter}') if e.timerId() != self.m_timer.timerId(): return #print('timerEvent Happening') #grabbedImage = image_handler.thumbnailImage.copy() #ret, frame = self.m_videoCapture.read() #ret = False #print(f'testimage size{testImage.shape}') if myTestClasse.image is not None: self.testImage = myTestClasse.image.copy() #print(f'thumbnail image :{self.testImage}') #self.frame = self.testImage.copy() #ret = True #cv2.imwrite('test3.png',self.testImage) else: return #if not ret: #print('timerEvent Stopping') #self.m_timer.stop() #return if self.m_busy == False: #print('start thread show image') #cv2.imwrite('test4.png',self.testImage) if self.testImage is not None: #localTest = self.testImage.copy() #print('start thread show image2') #cv2.imwrite('test4to5.png',self.testImage) #threading.Thread(target=self.process_image, args=(np.copy(self.testImage),)).start() self.process_image(self.testImage.copy()) @Slot(np.ndarray) def process_image(self, frame): #print('process image') cv2.imwrite('test5.png',frame) self.m_busy = True #print(f'flag is{self.m_busy}') #for f in self.m_filters: # frame = f.process_image(frame) image = CVCapture.ToQImage(frame) #if self._image == image: # self.m_busy = False # return self._image = image self.m_busy = False self.setImage() #QtCore.QMetaObject.invokeMethod(self,"setImage",QtCore.Qt.QueuedConnection) @staticmethod def ToQImage(im): if im is None: return QtGui.QImage() if im.dtype == np.uint8: if len(im.shape) == 2: qim = QtGui.QImage(im.data, im.shape[1], im.shape[0], im.strides[0], QtGui.QImage.Format_Indexed8) qim.setColorTable(gray_color_table) return qim.copy() elif len(im.shape) == 3: if im.shape[2] == 3: w, h, _ = im.shape rgb_image = cv2.cvtColor(im, cv2.COLOR_BGR2RGB) flip_image = cv2.flip(rgb_image, 1) qim = QtGui.QImage(flip_image.data, h, w, QtGui.QImage.Format_RGB888) return qim.copy() return QtGui.QImage() def getImage(self): return self._image @Slot() def setImage(self): self.imageReady.emit() def index(self): return self._index def setIndex(self, index): if self._index == index: return self._index = index self.indexChanged.emit() image = Property(QtGui.QImage, fget=getImage, notify=imageReady) index = Property(int, fget=index, fset=setIndex, notify=indexChanged) """
  • QStandardItem QtCore.Qt.ForegroundRole issue when out of focus

    Unsolved
    1
    0 Votes
    1 Posts
    495 Views
    No one has replied
  • PyQt5 - QPushButton to add row to a QTableView

    Moved Unsolved
    2
    0 Votes
    2 Posts
    1k Views
    P
    You can implement 'add row to QTableView' action for button in that way: from PyQt5.QtGui import QStandardItemModel, QStandardItem ... table = QTableView(...) table.setModel(QStandardtemModel()) addRowButton = QPushButton('Add row', ...) addRowButton.clicked.connect(lambda: table.model().insertRow(0, [QStandardItem('1'), QStandardItem('example'), ...])
  • Problem with custom ListView model and a custom item

    Solved pyside
    6
    0 Votes
    6 Posts
    1k Views
    eyllanescE
    @Tauri Read https://doc.qt.io/qt-5/qtquick-modelviewsdata-cppmodels.html#qvariantlist-based-model
  • qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in the virtualenv

    Solved
    3
    0 Votes
    3 Posts
    3k Views
    eyllanescE
    @Black-Cat execute sudo apt-get install '^libxcb.*-dev'
  • This topic is deleted!

    Unsolved
    2
    0 Votes
    2 Posts
    11 Views
  • How can i set baseUrl only once?

    Unsolved
    2
    0 Votes
    2 Posts
    303 Views
    eyllanescE
    You always have to set the baseUrl if you want to use setHtml, but if you want to repeat the code then create a method that does it: class Foo(Bar): def __init__(self, ...): super().__init(...) self._base_url = QUrl() self.base_url = QUrl.fromLocalFile(os.getcwd()+os.path.sep) self.webPage = ... @property def base_url(self): return self._base_url @base_url.setter def base_url(self, url): self._base_url = url def update_html(self, html): self.webPage.setHtml(html, self.base_url) then: self.update_html('<img src="image.png"/>');
  • How to change styleCheet on Event?

    Unsolved
    4
    0 Votes
    4 Posts
    477 Views
    JonBJ
    @levoxtrip I don't know anything about your "fading", but QTextEdit::append() always appends the text at the end. To insert somewhere else it looks like you must use QTextEdit::insertHtml/insertPlainText(), and those insert at the current cursor position, so you may need to move it with QTextEdit::moveCursor/setPosition() or similar.
  • How to add checkbox to context menu?

    Solved
    13
    0 Votes
    13 Posts
    4k Views
    jsulmJ
    @danielcharles Why do you post a link to a video handling C#? This is Qt forum...
  • How to know the version of Qt Designer?

    Unsolved
    2
    0 Votes
    2 Posts
    324 Views
    SGaistS
    Hi, IIRC, the about dialog that you can trigger from the help menu should give you this answer.
  • What IDE to view thread concurrency ?

    Unsolved
    1
    0 Votes
    1 Posts
    239 Views
    No one has replied
  • Python and android problem with deploy

    Unsolved qt for python python
    3
    0 Votes
    3 Posts
    612 Views
    M
    Well thanks you
  • Getting error messages from cmd window to plainTextEdit in QT

    Solved
    7
    0 Votes
    7 Posts
    1k Views
    S
    @SGaist Sorry for the little late reply. https://www.reddit.com/r/learnpython/comments/la5yze/how_to_display_error_messages_in_cmd_window_to/
  • App window too small and elements compressed when run

    Unsolved
    2
    0 Votes
    2 Posts
    629 Views
    SGaistS
    Hi and welcome to devnet, Are you using layouts to build your UI ?
  • Sorting the row based on the value of certain columns of QTableWidget

    Solved
    2
    0 Votes
    2 Posts
    2k Views
    JonBJ
    @Willkroken I need to check 3 different columns to check what order the rows should be arranged in If you stick with a QTableWidget, you have to sort your table by your criteria before you put the rows into the table, so go ahead and do so. Or it seems to me if the answer at https://stackoverflow.com/a/18652060/489865 using You can try to subclass the QTableWidgetItem and reimplement operator<() of it. works that is possible, but I don't know how you override an operator from Python. If you move to a QTableView and have your own model, you can interpose a QSortFilterProxyModel and override lessThan() to do your 3 column comparison.
  • MousePressEvent on a QWebEngineView

    Unsolved
    3
    0 Votes
    3 Posts
    2k Views
    eyllanescE
    @benyeyeye use focusProxy(): from PyQt5 import QtCore, QtWidgets, QtWebEngineWidgets # or # from PySide2 import QtCore, QtWidgets, QtWebEngineWidgets class BetterWebView(QtWebEngineWidgets.QWebEngineView): def __init__(self): super().__init__() self.load(QtCore.QUrl()) self.focusProxy().installEventFilter(self) def eventFilter(self, source, event): if ( self.focusProxy() is source and event.type() == QtCore.QEvent.MouseButtonPress ): print("ok") return super().eventFilter(source, event) if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) view = BetterWebView() view.load(QtCore.QUrl("https://www.qt.io")) view.show() sys.exit(app.exec_())
  • QtPy Interface and Plotly Dash server

    Unsolved
    2
    0 Votes
    2 Posts
    353 Views
    A
    So apparently, this is due to the Dash debug mode. I don't know why, however. Change this line app.run_server(debug = True) to app.run_server()
  • Unexpected behavior of QFileSystemModel

    Solved
    13
    1 Votes
    13 Posts
    2k Views
    M
    @JonB Thanks. I use os.path.normpath everywhere to get rid of this kind of problems :)