Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QWindow using QBackingStore behaves differently depending on the platform

QWindow using QBackingStore behaves differently depending on the platform

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 332 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    Yujeonja
    wrote on last edited by Yujeonja
    #1

    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.

    1. 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.

    2. Linux - Wayland
      Semi-transparent child window is blended with below parent windows color. This is the result exactly what I want.

    3. 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.

    1 Reply Last reply
    0
    • Kent-DorfmanK Offline
      Kent-DorfmanK Offline
      Kent-Dorfman
      wrote on last edited by
      #2

      @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.

      If you meet the AI on the road, kill it.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved