ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

Qt in python turned out to be a lot easier than I was expecting.

The full code is https://github.com/lucasw/vimjay/blob/master/scripts/display.py, and the important lines are

class RoundWindow(QtGui.QLabel): 
...
    self.setWindowFlags(Qt.FramelessWindowHint)

And in response to a new x,y and width and height:

    self.resize(roi.width, roi.height)
    self.move(roi.x_offset, roi.y_offset)

and converting the image for use in Qt:

def imageCallback(self, msg):
    np_arr = np.fromstring(msg.data, np.uint8)
    sz = (msg.height, msg.width, msg.step / msg.width)
    image = np.reshape(np_arr, sz)

    ... do some stuff with image_pre ...

     self.qimage = QImage.rgbSwapped(QImage(image.tostring(), 
            self.wd, self.ht, 
            QImage.Format_RGB888))

Do this in qt thread to update the display, not the callback thread:

    self.setPixmap(QtGui.QPixmap.fromImage(self.qimage))

(I think my code might lack some thread safetyness regarding self.qimage)

Qt in python turned out to be a lot easier than I was expecting.

The full code is https://github.com/lucasw/vimjay/blob/master/scripts/display.py, and the important lines are

class RoundWindow(QtGui.QLabel): UndecoratedWindow(QtGui.QLabel): 
...
    self.setWindowFlags(Qt.FramelessWindowHint)

And in response to a new x,y and width and height:

    self.resize(roi.width, roi.height)
    self.move(roi.x_offset, roi.y_offset)

and converting the image for use in Qt:

def imageCallback(self, msg):
    np_arr = np.fromstring(msg.data, np.uint8)
    sz = (msg.height, msg.width, msg.step / msg.width)
    image = np.reshape(np_arr, sz)

    ... do some stuff with image_pre ...

     self.qimage = QImage.rgbSwapped(QImage(image.tostring(), 
            self.wd, self.ht, 
            QImage.Format_RGB888))

Do this in qt thread to update the display, not the callback thread:

    self.setPixmap(QtGui.QPixmap.fromImage(self.qimage))

(I think my code might lack some thread safetyness regarding self.qimage)

Qt in python turned out to be a lot easier than I was expecting.

The full code is https://github.com/lucasw/vimjay/blob/master/scripts/display.py, and the important lines are

class UndecoratedWindow(QtGui.QLabel): 
...
    self.setWindowFlags(Qt.FramelessWindowHint)

And in response to a new x,y and width and height:

    self.resize(roi.width, roi.height)
    self.move(roi.x_offset, roi.y_offset)

and converting the image for use in Qt:

def imageCallback(self, msg):
    np_arr = np.fromstring(msg.data, np.uint8)
    sz = (msg.height, msg.width, msg.step / msg.width)
    image = np.reshape(np_arr, sz)

    ... do some stuff with image_pre image to keep aspect raio ...

     self.qimage = QImage.rgbSwapped(QImage(image.tostring(), 
            self.wd, self.ht, 
            QImage.Format_RGB888))

Do this in qt thread to update the display, not the callback thread:

    self.setPixmap(QtGui.QPixmap.fromImage(self.qimage))

(I think my code might lack some thread safetyness regarding self.qimage)