diff options
4 files changed, 19 insertions, 29 deletions
diff --git a/examples/quick/quickwidgets/qquickviewcomparison/main.cpp b/examples/quick/quickwidgets/qquickviewcomparison/main.cpp index bbe97a947f..7e45e42527 100644 --- a/examples/quick/quickwidgets/qquickviewcomparison/main.cpp +++ b/examples/quick/quickwidgets/qquickviewcomparison/main.cpp @@ -48,7 +48,13 @@ int main(int argc, char **argv) QApplication app(argc, argv); - MainWindow widgetWindow; + bool transparency = QCoreApplication::arguments().contains(QStringLiteral("--transparent")); + MainWindow widgetWindow(transparency); + if (transparency) { + widgetWindow.setAttribute(Qt::WA_TranslucentBackground); + widgetWindow.setAttribute(Qt::WA_NoSystemBackground, false); + } + widgetWindow.resize(1024, 768); widgetWindow.show(); diff --git a/examples/quick/quickwidgets/qquickviewcomparison/mainwindow.cpp b/examples/quick/quickwidgets/qquickviewcomparison/mainwindow.cpp index dce89d6b18..078d8e7e03 100644 --- a/examples/quick/quickwidgets/qquickviewcomparison/mainwindow.cpp +++ b/examples/quick/quickwidgets/qquickviewcomparison/mainwindow.cpp @@ -47,10 +47,10 @@ #include <QLabel> #include <QQuickItem> -MainWindow::MainWindow() +MainWindow::MainWindow(bool transparency) : m_currentView(0), m_currentRootObject(0), - m_transparent(false) + m_transparent(transparency) { QVBoxLayout *layout = new QVBoxLayout; @@ -103,13 +103,6 @@ MainWindow::MainWindow() connect(m_checkboxOverlayVisible, &QCheckBox::toggled, m_overlayLabel, &QWidget::setVisible); layout->addWidget(m_checkboxOverlayVisible); - m_checkboxTransparent = new QCheckBox(tr("Transparent background in QQuickWidget")); - connect(m_radioWidget, &QCheckBox::toggled, m_checkboxTransparent, &QWidget::setEnabled); -#ifdef Q_OS_LINUX - connect(m_checkboxTransparent, &QCheckBox::toggled, this, &MainWindow::onTransparentChanged); - layout->addWidget(m_checkboxTransparent); -#endif - setLayout(layout); updateView(); @@ -170,10 +163,8 @@ void MainWindow::updateView() switchTo(QWidget::createWindowContainer(quickView)); } else if (m_state == UseWidget) { QQuickWidget *quickWidget = new QQuickWidget; - if (m_transparent) { + if (m_transparent) quickWidget->setClearColor(Qt::transparent); - quickWidget->setAttribute(Qt::WA_TranslucentBackground); - } quickWidget->setFormat(m_format); quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView); connect(quickWidget, &QQuickWidget::statusChanged, this, &MainWindow::onStatusChangedWidget); @@ -186,7 +177,8 @@ void MainWindow::updateView() if (m_currentRootObject) { m_currentRootObject->setProperty("currentText", text); m_currentRootObject->setProperty("multisample", m_checkboxMultiSample->isChecked()); - m_currentRootObject->setProperty("translucency", m_transparent); + if (!QCoreApplication::arguments().contains(QStringLiteral("--no_render_alpha"))) + m_currentRootObject->setProperty("translucency", m_transparent); } m_overlayLabel->raise(); @@ -242,9 +234,3 @@ void MainWindow::onSceneGraphError(QQuickWindow::SceneGraphError error, const QS { m_labelStatus->setText(tr("Scenegraph error %1: %2").arg(error).arg(message)); } - -void MainWindow::onTransparentChanged(bool enabled) -{ - m_transparent = enabled; - updateView(); -} diff --git a/examples/quick/quickwidgets/qquickviewcomparison/mainwindow.h b/examples/quick/quickwidgets/qquickviewcomparison/mainwindow.h index c58523f675..5b86c93f38 100644 --- a/examples/quick/quickwidgets/qquickviewcomparison/mainwindow.h +++ b/examples/quick/quickwidgets/qquickviewcomparison/mainwindow.h @@ -53,7 +53,7 @@ QT_FORWARD_DECLARE_CLASS(QLayout) class MainWindow : public QWidget { public: - MainWindow(); + MainWindow(bool transparency); protected: void resizeEvent(QResizeEvent*); @@ -63,7 +63,6 @@ private slots: void onStatusChangedView(QQuickView::Status status); void onStatusChangedWidget(QQuickWidget::Status status); void onSceneGraphError(QQuickWindow::SceneGraphError error, const QString &message); - void onTransparentChanged(bool enabled); private: void switchTo(QWidget *view); @@ -86,8 +85,6 @@ private: QSurfaceFormat m_format; - QCheckBox *m_checkboxTransparent; - bool m_transparent; }; diff --git a/src/quickwidgets/qquickwidget.cpp b/src/quickwidgets/qquickwidget.cpp index 47bcabc115..9cfec370f9 100644 --- a/src/quickwidgets/qquickwidget.cpp +++ b/src/quickwidgets/qquickwidget.cpp @@ -345,8 +345,8 @@ QObject *QQuickWidgetPrivate::focusObject() This limitation only applies when there are other widgets underneath the QQuickWidget inside the same window. Making the window semi-transparent, with other applications and the desktop visible in the background, is done in the traditional way: Set - Qt::WA_TranslucentBackground and change the Qt Quick Scenegraph's clear color to - Qt::transparent via setClearColor(). + Qt::WA_TranslucentBackground on the top-level window, request an alpha channel, and + change the Qt Quick Scenegraph's clear color to Qt::transparent via setClearColor(). \sa {Exposing Attributes of C++ Types to QML}, {Qt Quick Widgets Example}, QQuickView */ @@ -1293,9 +1293,10 @@ QImage QQuickWidget::grabFramebuffer() const /*! Sets the clear \a color. By default this is an opaque color. - To get a semi- or fully transparent QQuickWidget, call this function with \a - color set to Qt::transparent and set the Qt::WA_TranslucentBackground widget - attribute. + To get a semi-transparent QQuickWidget, call this function with + \a color set to Qt::transparent, set the Qt::WA_TranslucentBackground + widget attribute on the top-level window, and request an alpha + channel via setFormat(). \sa QQuickWindow::setColor() */ |