Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] How can I have a irregular-shaped window with Qt 5.2? WA_TranslucentBackground doesn't work on Qt 5.2 Windows
Forum Updated to NodeBB v4.3 + New Features

[Solved] How can I have a irregular-shaped window with Qt 5.2? WA_TranslucentBackground doesn't work on Qt 5.2 Windows

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 4.5k Views 1 Watching
  • 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.
  • C Offline
    C Offline
    cidhuang
    wrote on last edited by
    #1

    Hi,

    The code below opens a borderless window with qml UI and black background.

    @
    #include <QQuickView>
    #include "mainwindow.h"

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent)
    {
    setFixedSize(300, 300);
    setWindowFlags(Qt::FramelessWindowHint);
    setStyleSheet("background :transparent;");
    //setAttribute(Qt::WA_TranslucentBackground, true);

    view = new QQuickView();
    view->setSource(QUrl("main.qml"));
    view->setColor(QColor(Qt::transparent));
    
    container = QWidget::createWindowContainer(view, this);
    container->setFixedSize(300, 300);
    container->setGeometry(10, 10, 30, 30);
    container->setFocusPolicy(Qt::TabFocus);
    

    }

    MainWindow::~MainWindow()
    {
    delete container;
    delete view;
    }
    @

    But, if I remove the remark of below line, the window becomes completely invisible.

    @
    setAttribute(Qt::WA_TranslucentBackground, true);
    @

    Is it a bug?

    How can I have a irregular-shaped window with Qt 5.2?

    Thank you,

    Cid

    1 Reply Last reply
    0
    • J Offline
      J Offline
      janp
      wrote on last edited by
      #2

      Bump... Anyone has a solution for this?

      I have run into similar problem. Transparency works fine just for QQuickView window alone:

      @
      view = new QQuickView();
      view->setSource(QUrl("main.qml"));
      view->setColor(QColor(Qt::transparent));
      view->show();
      @

      But once I try to create a window container for my QQuickView with QWidget::createWindowContainer(...), I get either opaque black background or invisible nothing.

      Is this a bug? Is there at least a workaround?

      1 Reply Last reply
      0
      • B Offline
        B Offline
        bwilli
        wrote on last edited by
        #3

        Hi,

        I have the same problem - did you ever get a workaround for this?

        Thank you,
        Bruno

        1 Reply Last reply
        0
        • V Offline
          V Offline
          Veiron
          wrote on last edited by
          #4

          Hi,
          I have the same problem
          Can anybody help?
          Thank you,

          1 Reply Last reply
          0
          • C Offline
            C Offline
            cidhuang
            wrote on last edited by
            #5

            There are 2 ways. One is QWidget with QDeclarativeView like Qt 4. Another is QQuickView.

            For the former, WA_TranslucentBackground works, but Qml 2 not support.

            For the latter, a mask picture is required. Below is the sample code:

            @
            MainView::MainView(QQuickView *parent) :
            QQuickView(parent)
            {
            Qt::WindowFlags _flags = flags();
            _flags |= Qt::FramelessWindowHint;
            setFlags(_flags);
            setSource(QStringLiteral("default/main.qml"));

            show();
            

            setMask(QPixmap("default/mask.png").mask());
            }

            @

            mask.png is the picture with alpha channel. It is the shape of window shape.

            Hope this helps to you.

            Mao-Yeh

            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