I'm trying to draw an X11 Pixmap to a QWidget
.
In the past using Qt4.x I would leverage QPixmap::fromX11Pixmap
to create a QPixmap
that I could easily use in painting. However this function has been removed in Qt5 and from my knowledge the functionality has not been made available elsewhere in the Qt Framework.
While I have been able to create and allocate the X11 Pixmap I haven't been able to find any solution to perform the painting. Any suggestions/solutions welcomed!
I had the same problem and didn't find any answer. After doing some hacks I came to this solution.
// Initialize your X11 enviroment.
Display* display ...
Pixmap pixmap ...
/* Do your pixmap drawing HERE */
// Make sure all drawing have been done
XFlush(display);
// Convert your Pixmap to XImage
XImage *image = XGetImage(display, pixmap, 0, 0, width, height, 0xFFFFFFFF, ZPixmap);
// Convert XImage to QImage
QImage tempImage = qimageFromXImage(image);
// Destroy temporal XImage
XDestroyImage(image);
// Finally create a QPixmap
QPixmap finalPixmap = QPixmap::fromImage(tempImage);
The code for function qimageFromXImage(...)
can be found at https://github.com/adobe/webkit/blob/master/Source/WebCore/plugins/qt/QtX11ImageConversion.h You can copy the header and implementation to your source tree.
Problem solved! Can be used with a QQuickPaintedItem or QGraphicsItem.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.