Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Method QWidget::createWindowContainer and background
Qt 6.11 is out! See what's new in the release blog

Method QWidget::createWindowContainer and background

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 1 Posters 1.2k Views
  • 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.
  • S Offline
    S Offline
    SHRED4RED
    wrote on last edited by
    #1

    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)?

    S 1 Reply Last reply
    0
    • S SHRED4RED

      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)?

      S Offline
      S Offline
      SHRED4RED
      wrote on last edited by
      #2

      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

      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