Issue with Frameless Window and createWindowContainer Causing UI Not to Refresh on Qt 5.15 (Windows)
-
wrote 16 days ago last edited by
I am encountering a problem using Qt 5.15 on the Windows platform. I have created a minimum reproducible example to demonstrate the issue.
The issue arises when I use Qt::FramelessWindowHint and Qt::WA_TranslucentBackground for a frameless window, and then wrap this window with QWidget::createWindowContainer. After doing so, the UI of the frameless window becomes unresponsive and does not refresh properly.|
Here is the code snippet:
#include <QApplication> #include <QWidget> #include <QLabel> #include <QVBoxLayout> #include <QPalette> #include <QWindow> #include <QPushButton> #include <QDateTime> int main(int argc, char *argv[]) { QApplication a(argc, argv); QWidget* mainWindow = new QWidget(); mainWindow->setWindowTitle("Main Window"); mainWindow->resize(300, 400); QPalette pal1; pal1.setColor(QPalette::Window, QColor(200, 230, 255)); // Light blue mainWindow->setAutoFillBackground(true); mainWindow->setPalette(pal1); QVBoxLayout* layout1 = new QVBoxLayout(mainWindow); QLabel* label1 = new QLabel("Hello, yaminet1024!"); label1->setAlignment(Qt::AlignCenter); layout1->addWidget(label1); QWidget* framelessWindow = new QWidget(); framelessWindow->setWindowFlags(Qt::FramelessWindowHint); framelessWindow->setAttribute(Qt::WA_TranslucentBackground); framelessWindow->resize(200, 150); QVBoxLayout* layout2 = new QVBoxLayout(framelessWindow); QLabel* label2 = new QLabel("2025-04-17 17:23:07"); label2->setAlignment(Qt::AlignCenter); layout2->addWidget(label2); // Add refresh button QPushButton* refreshBtn = new QPushButton("Refresh"); refreshBtn->setFixedSize(80, 30); refreshBtn->setStyleSheet( "QPushButton { background: #FFB6C1; border: 1px solid #FF69B4; border-radius: 5px; }" "QPushButton:hover { background: #FFC0CB; }" "QPushButton:pressed { background: #FF1493; }" ); // Connect button click to update text QObject::connect(refreshBtn, &QPushButton::clicked, [label2](){ QDateTime currentTime = QDateTime::currentDateTime(); label2->setText(currentTime.toString("yyyy-MM-dd hh:mm:ss")); }); layout2->addWidget(refreshBtn, 0, Qt::AlignHCenter); framelessWindow->show(); QWindow* window = QWindow::fromWinId(framelessWindow->winId()); QWidget* container = QWidget::createWindowContainer(window, mainWindow); container->setMinimumSize(200, 150); layout1->addWidget(container); mainWindow->show(); return a.exec(); }
In this example:
The framelessWindow is set with the Qt::FramelessWindowHint and Qt::WA_TranslucentBackground flags.
The frameless window is then wrapped with QWidget::createWindowContainer.
The Refresh button is supposed to update the timestamp shown in the framelessWindow. However, after wrapping the frameless window in createWindowContainer, the UI becomes unresponsive and fails to refresh properly.I suspect this might be a limitation or a bug related to the use of createWindowContainer with frameless windows using these specific flags.
Has anyone encountered a similar issue or knows of a workaround? Any help is greatly appreciated!
Thank you!
-
I tested it with a recent Qt6 version and could not see any pushbutton at all.
1/2