QWindow using QBackingStore behaves differently depending on the platform
-
I'm testing QWindow with QBackingStore to draw a window. I started from this example: https://doc.qt.io/qt-5/qtgui-rasterwindow-example.html
And I added some code in the constructor for alpha channel.
QSurfaceFormat format; format.setAlphaBufferSize(8); this->setFormat(format);I need semi-transparent content so I modified the code as below.
void Window::setColor(const QColor &color) { this->m_color = color; } void Window::renderNow() { if (!isExposed()) { return; } QRect rect(0, 0, width(), height()); m_backingStore->beginPaint(rect); QPaintDevice *device = m_backingStore->paintDevice(); QPainter painter(device); if (this->parent() == nullptr) { painter.fillRect(0, 0, width(), height(), QColor(255, 0, 0, 255)); } else { painter.fillRect(0, 0, width(), height(), this->m_color); } render(&painter); painter.end(); this->m_backingStore->endPaint(); this->m_backingStore->flush(rect); }And I want to draw some rectangles in toplevel window so I created sub-class of QWindow as a child of the window.
QApplication a(argc, argv); Window win; Window win2(&win); win2.setWidth(20); win2.setHeight(20); win2.setX(0); win2.setY(0); win2.setColor(QColor(100, 100, 255, 100)); win.show(); win2.show(); return a.exec();But the result was different across the platforms.
-
Linux - X11
Child window is transparent through the parent window. It means, while parent window(red) is opaque, the area of child window is semi-transparent so I can see the content of other window below my window. -
Linux - Wayland
Semi-transparent child window is blended with below parent windows color. This is the result exactly what I want. -
Windows
Child window is not transparent as there is black background under the window. Transparency is not working.
Why are the results different for different platforms? Is there something I missed? Are these undefined behaviors? If then, what should I do for the result that I want as second one.
I used Qt 5.15.2 for all platforms.
-
-
@Yujeonja said in QWindow using QBackingStore behaves differently depending on the platform:
Why are the results different for different platforms?
because each GUI handles it differently and has differing capabilities.
Is there something I missed?
No.