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. Background image or transparency from Style Sheet does not show on QWidget
Forum Updated to NodeBB v4.3 + New Features

Background image or transparency from Style Sheet does not show on QWidget

Scheduled Pinned Locked Moved General and Desktop
15 Posts 3 Posters 26.4k 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.
  • EddyE Offline
    EddyE Offline
    Eddy
    wrote on last edited by
    #5

    What OS are you on? If windows is your target, then "this qt labs article ":http://labs.qt.nokia.com/2009/09/15/using-blur-behind-on-windows/ could interest you.

    Qt Certified Specialist
    www.edalsolutions.be

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jesuisbenjamin
      wrote on last edited by
      #6

      PS: I have partly found an answer regarding the background image.
      Changing adding a preceding dot to the path seems to help locating the file:
      @QToolBar {background-image: url(./wood.jpg)}@

      However, the same applied to the MainWindow does not work:
      @MainWindow {background-image: url(./wood.jpg)}@

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jesuisbenjamin
        wrote on last edited by
        #7

        @Eddy: Target is Linux in general, I am working on Ubuntu + Gnome at the moment.

        [quote author="Eddy" date="1314551129"]What OS are you on? If windows is your target, then "this qt labs article ":http://labs.qt.nokia.com/2009/09/15/using-blur-behind-on-windows/ could interest you.[/quote]

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jesuisbenjamin
          wrote on last edited by
          #8

          Rahul: I am working with Python, and I believe the "build" directory is something of C (?). Anyway, as stated later, using "./wood.jpg" as a path pointed to the file in the same directory.

          As to set the window transparent, I have tried:
          @self.setAttribute(QtCore.Qt.WA_TranslucentBackground, True)@
          But that make the entire main widget transparent, and it is not the desired result: I wan the partial opacity of the main widget to remain, and the black background it is painted on to be fully transparent.

          [quote author="Rahul Das" date="1314551126"]If you are using relative path, make sure you have the image , relative to the deploy/ build directory.

          In this case, copying the wood.jpg to your build dir solves the problem.

          Edit : You can set the opacity of the window, to make it transparent :)[/quote]

          1 Reply Last reply
          0
          • R Offline
            R Offline
            Rahul Das
            wrote on last edited by
            #9

            Copying the image to the build directory and setting the style sheet as @background-image: url(./Jellyfish.jpg);@ worked for me.

            And "opacity":http://doc.qt.nokia.com/latest/qwidget.html#windowOpacity-prop as well!

            and sorry , am not familiar with Python :(


            Declaration of (Platform) independence.

            1 Reply Last reply
            0
            • J Offline
              J Offline
              jesuisbenjamin
              wrote on last edited by
              #10

              As stated above "./wood.jpg" worked indeed (with the file placed in the same directory as the source file). But why that does not work for the MainWindow() i don't know :(

              As to setting opacity, it worked indeed, but on all widgets, whereas I want the main widget only to be translucent and not its children.

              [quote author="Rahul Das" date="1314551605"]Copying the image to the build directory and setting the style sheet as @background-image: url(./Jellyfish.jpg);@ worked for me.

              And "opacity":http://doc.qt.nokia.com/latest/qwidget.html#windowOpacity-prop as well!

              and sorry , am not familiar with Python :([/quote]

              1 Reply Last reply
              0
              • R Offline
                R Offline
                Rahul Das
                wrote on last edited by
                #11

                I assume you are trying to change the background of the centralWidget. :) Are you ?

                Your mainwindow has a centralWidget right ? set the style sheet of this central widget. What do you see ?


                Declaration of (Platform) independence.

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  jesuisbenjamin
                  wrote on last edited by
                  #12

                  Rahul, thanks again.

                  Perhaps it is easier if I show what I would like to achieve, see this mockup:

                  !https://lh3.googleusercontent.com/-P-DDWz3XDyE/Tlo05_ABj6I/AAAAAAAACgM/vXD464ndnIU/s720/dash2.png(Mockup)!

                  To achieve this, I have to change the background of the main widget to show the wood texture. That didn't work so far. I am not working with a QMainWindow() however, so there is no central widget I believe. The main window of my application inherits from a QWidget().

                  The alternative is to make the main widget completely transparent, which I achieved with setting property: @self.setAttribute(QtCore.Qt.WA_TranslucentBackground, True)@

                  I would also try to make the background semi-transparent, using an alpha value of eg. 50% in the style sheet: which does not work so far.

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    jesuisbenjamin
                    wrote on last edited by
                    #13

                    Update:

                    Using a tip from "another post":http://www.qtforum.org/article/23474/background-image-for-qwidget.html#post86564, I've added the following to my code:
                    @self.palette = QtGui.QPalette()
                    self.palette.setBrush(self.backgroundRole(), QtGui.QBrush(QtGui.QImage("./wood.jpg")))
                    self.setPalette(self.palette)@

                    It worked, so it means it is possible. Now I need to do the same using a style sheet, please let me know if you have an idea how to make this happen.

                    Thanks.

                    1 Reply Last reply
                    0
                    • J Offline
                      J Offline
                      jesuisbenjamin
                      wrote on last edited by
                      #14

                      Update:

                      On "StackOverflow":http://stackoverflow.com/questions/4830517/qt-stylesheet-background-color-yes-background-image-no it is porposed to derive the MainWidget from QFrame() instead of QWidget() and setting the background image does work then.

                      This problem is "recurrent":http://developer.qt.nokia.com/forums/viewthread/4713. But there's no clear solution to be seen anywhere except for the above.
                      Any thoughts?

                      Cheers.

                      1 Reply Last reply
                      0
                      • R Offline
                        R Offline
                        Rahul Das
                        wrote on last edited by
                        #15

                        I tried with pallet, and for me also it failed. May be we should look for some other work around to appear the same,like its mentioned in stack overflow.


                        Declaration of (Platform) independence.

                        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