Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

qwidget can`t effect transparent background



  • hello,

    I making fullscreen window by 2 Layers.
    but I can`t effect transparent background with foreground layer.
    (background is fully white.)

    please check this code in my fault.


    Widget::Widget(QWidget *parent)
    : QWidget(parent)
    {
    QPalette pal;
    QPixmap bg(":/Image/bkgnd.jpg");
    pal.setBrush(QPalette::Background,bg);
    setAutoFillBackground((false));
    setPalette(pal);

    // This code is working.(Background Layer)
    this->setWindowFlags(Qt::FramelessWindowHint);
    this->setAttribute(Qt::WA_TranslucentBackground);
    
    QQuickView *qmlView = new QQuickView;
    qmlView->setSource(QUrl::fromLocalFile("QML/main.qml"));
    
    QWidget *container = QWidget::createWindowContainer(qmlView, this);
    container->setFixedSize(1920,1080);
    container->setAutoFillBackground(false);
    
    // Problem : This code is not working.(Foreground Layer)
    container->setWindowFlags(Qt::FramelessWindowHint);
    container->setAttribute(Qt::WA_TranslucentBackground);
    
    QVBoxLayout *layout = new QVBoxLayout(this);
    setLayout(layout);
    setGeometry(container->geometry());
    layout->addWidget(container);
    

    }


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    I'm really not sure you can have a transparent widget with a QtQuick content.

    What kind of GUI are you trying to build like that ?



  • @SGaist hello, thanks for kindly reply.
    I want to this;
    0_1555286785495_screenshot_addtext_3.png


  • Lifetime Qt Champion

    Why mix widgets and QtQuick ?



  • @SGaist I want to make qml GUI(QQuickView) on the current widget code(QWidget).
    anyway, I think another way to this;
    but I can`t merge 2 GUIs(QWidget + QQuickView).

    /////main.cpp
    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);
    QQuickView *view = new QQuickView();
    Mapwidget *mapwidget = new Mapwidget();
    view->setSource(QUrl("qrc:/QML/main.qml"));
    view->setColor(QColor(Qt::transparent));

    QHBoxLayout *layout = new QHBoxLayout(mapwidget);
    QWidget *container = QWidget::createWindowContainer(view);
    container->setFixedSize(1920,1080);
    container->setAutoFillBackground(false);

    mapwidget->setLayout(layout);
    layout->setMargin(0);
    layout->addWidget(container);
    mapwidget->showFullScreen();
    return app.exec();
    }

    ///mapwidget.cpp
    Mapwidget::Mapwidget(QWidget *parent)
    : QWidget(parent)
    {
    QPalette pal;
    QPixmap bg(":/Image/bkgnd.jpg");
    pal.setBrush(QPalette::Background,bg);
    setPalette(pal);
    }


  • Moderators

    Mixing QML and QWidgets in such a way that one is (partially)transparent to the other is, as far as I know, not possible.

    Or at least I never managed it.

    May very well be because they rely on totally different rendering mechanics.


  • Lifetime Qt Champion

    You have QQuickWidget that you can use to have a QtQuick interface in a widget application. However, I don't think it will solve your problem.

    From your code, I don't understand the use of QWidget for just the background of your GUI. Why not go full QtQuick ?


Log in to reply