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

Method QWidget::createWindowContainer and background



  • I want to make Label with icon and text and a transparent background:
    qml file:

    Item {
    property alias labelText: label.text
    
        Image {
            id: pic
            source: "qrc:/../../Desktop/avatar.png"
        }
    
        Label {
            id: label
            text: "This text should change... This text should change... This text should change... This text should change... This text should change..."
            width: 200
            textFormat: "RichText"
            color: "red"
            font.pixelSize: 12
            anchors.left: pic.right
            anchors.leftMargin: 10
            wrapMode: Text.Wrap
            background: Rectangle
            {
                color: "black"
                radius: 5
            }
        }
    }
    

    cpp:

    QQuickView* view = new QQuickView();
    
    QWidget* container = QWidget::createWindowContainer(view, ui->centralWidget);
    container->setMinimumSize(320,80);
    container->setMaximumSize(320,80);
    container->setStyleSheet("QWidget {background-color: rgb(23,58,104)}");
    
    view->setSource(QUrl("qrc:/MsgLabel.qml"));
    
    ui->verticalLayout->addWidget(container);
    

    0_1527591440574_qml.PNG

    I try change background color of widget but nothing... How to make transparent background (white area is bad)?



  • found such a solution:

    QQuickWidget* qq = new QQuickWidget(QUrl("qrc:/MsgLabel.qml"), ui->widget);
    qq->resize(320,80);
    qq->setAttribute(Qt::WA_AlwaysStackOnTop);
    qq->setClearColor(Qt::transparent);
    ui->verticalLayout_2->addWidget(qq, 0 , Qt::AlignBottom | Qt::AlignLeft);
    

    0_1527593150186_qml2.PNG


Log in to reply