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. Transparency Behaviour Different in OSX/WIndows and Linux

Transparency Behaviour Different in OSX/WIndows and Linux

Scheduled Pinned Locked Moved General and Desktop
qwidgetwindowtranspare
1 Posts 1 Posters 919 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.
  • R Offline
    R Offline
    RScreene
    wrote on last edited by
    #1

    I am attempting to write a screenshare application using Qt5. It works well on OSX and Windows but the same code does not work in the same way under Linux.

    The following files give a simple demonstation of my problem. I have a frameless, transparent, always-on-top QWidget on which I have a QPushButton. When I click the QPushButton I expect
    the handler to be called. When an input event occurs anywhere else in the QWidget I would like the window beneath the widget to receive the
    event.

    window.h:

    #include <QWidget>
    
    class Window : public QWidget
    {
    Q_OBJECT
    
    public:
        Window();
    
    protected:
        void paintEvent(QPaintEvent *pEvent);
    
    private slots:
        void buttonPressed();
    };
    

    window.cpp:

    #include <QDebug>
    #include <QPainter>
    #include <QColor>
    #include <QPen>
    #include <QPushButton>
    #include <QVBoxLayout>
    
    #include "window.h"
    
    Window::Window() {
        setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
    
        setAttribute(Qt::WA_TranslucentBackground, true);
        setStyleSheet("background: transparent;");
    
        QVBoxLayout *pLayout = new QVBoxLayout();
    
        QPushButton *pButton = new QPushButton("Press Me");
        pButton->setStyleSheet("background-color: green; border: none;");
        connect(pButton, &QPushButton::pressed, this, &Window::buttonPressed);
        pLayout->addWidget(pButton);
    
        QWidget *pView = new QWidget(this, Qt::WindowTransparentForInput);
        pLayout->addWidget(pView);
    
        setLayout(pLayout);
    
        resize(300, 300);
    }
    
    void Window::paintEvent(QPaintEvent *pEvent) {
        int borderWidth = 5;
        QPainter painter(this);
    
        QColor colour("red");
    
        QPen pen(colour, borderWidth);
        painter.setPen(pen);
        painter.drawRect(rect());
    
        QWidget::paintEvent(pEvent);
    }
    
    void Window::buttonPressed() {
        qDebug() << "PRESSED BUTTON";
    }
    

    main.cpp:

    #include <QApplication>
    #include <QDebug>
    #include "window.h"
    
    
    int main(int argc, char *argv[]) {
        QApplication app(argc, argv);
    
        Window window;
    
        window.show();
    
        return app.exec();
    }
    

    This works well on OSX and Windows. However, if I use exactly the same code on Linux, the QPushButton works but any input events in the other areas of the widget do not get passed through to the lower windows. If I add the Qt::WindowTransparentForInput window flag then on all OSs it is not possible to interact with the QPushButton.

    Is there any way in which the OSX/Windows functionlity can be achieved on Linux? I would be wiling to consider native code if necessary!

    Many thanks for looking.

    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