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 to get an simple transparent window

[solved] how to get an simple transparent window

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 80.3k 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
    Schneidi
    wrote on last edited by
    #1

    Hi, I try to build a simple MainWindow which has an transparent background.

    I saw so many approaches out there but nothing works.
    Some How to's arn't working and others are ...

    "This":http://developer.qt.nokia.com/faq/answer/how_can_i_have_a_partially_transparent_pixmap_on_my_toplevel_window for example isn't really useful or ?

    Do I have a chance to just get the background of my main window transparent without hacking around ?
    I know that there is a way with masks but I didn't get this to work.

    Do anybody has an example of how to do that the right way.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      markus.liebe
      wrote on last edited by
      #2

      The following worked for me. Do it in the constructor of your MainWindow:

      @ setStyleSheet("background:transparent;");
      setAttribute(Qt::WA_TranslucentBackground);
      setWindowFlags(Qt::FramelessWindowHint);@

      The only problem that I am facing with that is: On KDE4 I have enabled window shadows. The code above makes the window transparent, but the shadow remains visible... =)

      1 Reply Last reply
      1
      • S Offline
        S Offline
        Schneidi
        wrote on last edited by
        #3

        Heh, ok I will try this and the shadow thing should be no problem because I set a QDeclarativeView as centralWidget I just don't want the Widget based window to be appear. So it could look like my qml window is shadowing.

        Hope this will work. When I try to use a Mask all I get is a black window background.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Schneidi
          wrote on last edited by
          #4

          Ok I tried this out and it seems to work partially, the mainWindow on its own disapear but If I have
          a Widget on that window it looks like I loose the opacity effect.

          I have a QDeclarativeView as Centralwidget with an area that is halfway transparent but I can't look through the underlying mainWindow the transparency effect is gone.

          How can I fix that ?
          Do I have to get the QDeclarativeView to be transparent too ?

          I tried this already but it doesn't seem to work.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            markus.liebe
            wrote on last edited by
            #5

            Hi.

            I am not quite sure what you want to do, but for me it works like that (in the Constructor of the MainWindow):
            @
            QDeclarativeView* v = new QDeclarativeView;
            setCentralWidget(v);

            v->setSource(QUrl("qrc:/test.qml"));
            
            v->setStyleSheet("background:transparent");
            v->setAttribute(Qt::WA_TranslucentBackground);
            v->setWindowFlags(Qt::FramelessWindowHint);
            
            setStyleSheet("background:transparent;");
            setAttribute(Qt::WA_TranslucentBackground);
            setWindowFlags(Qt::FramelessWindowHint);@
            

            using the following QML from the documentation:

            @import Qt 4.7

            Item {
            Rectangle {
            opacity: 0.5
            color: "red"
            width: 100; height: 100
            Rectangle {
            color: "blue"
            x: 50; y: 50; width: 100; height: 100
            }
            }
            }
            @

            Regards,
            Markus

            1 Reply Last reply
            1
            • S Offline
              S Offline
              Schneidi
              wrote on last edited by
              #6

              Hey thank you Markus, your example works perfectly, this is exactly what I was searching for.

              two Thumbs up !!

              1 Reply Last reply
              0
              • M Offline
                M Offline
                markus.liebe
                wrote on last edited by
                #7

                Nice! =) Glad to be of help.
                If you want to, you can edit your original post title and add a [solved] in front. So others know that the topic is solved by looking at the title.

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  Cupidvogel
                  wrote on last edited by Cupidvogel
                  #8

                  Sorry to bump it up, but I have posted a question and haven't got an answer yet. The solution with Qt::WA_TranslucentBackground works fine, but my widget has other sub-widgets (QImages) rendered through OpenGL, and using this property on the parent widget makes those images appear blank in Windows. Is there any other way of achieving this, i.e, without using Qt::WA_TranslucentBackground, even if it has to be rather hackish?

                  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