QLabe and Transparency

  • Jochen Weiss

    Jochen Weiss - 2008-12-12

    I'm to stupid to add aQLabel with (semi-)transparency and to change the font color. Can anyone help with this "simple" question ?

    Did some search in Google, but found no answer

    • Martin Zibricky

      Martin Zibricky - 2008-12-12

      Could you be more specific and post any code example you are playing with?

    • celsowm

      celsowm - 2008-12-12

      What is your purpose? Shadows  for the slideshow? Draw shadows behind text?

      • Jochen Weiss

        Jochen Weiss - 2008-12-12

        Draw text on top of a video like "On Screen Display" OSD.
        Because my QMainWindow has a black background, the QLabel inherit this from it. No I have a label with black fonts on a black background :-(

        class MyMainWindow(QtGui.QMainWindow):
             def __init__(self):
                self.player = Phonon.VideoPlayer(Phonon.VideoCategory,self)
                self.setStyleSheet("background-color: rgb(0, 0, 0);")


        self.labelVideoSizex = QtGui.QLabel(self)
        self.labelVideoSizex.setGeometry(QtCore.QRect(410, 220, 61, 31))

        Here I want to change the Text Color and set the background transparend

        • Martin Zibricky

          Martin Zibricky - 2008-12-12

          Are you trying to incorporate this code into the videoplayer example you've created recently?

          If so, could you commit the code to svn?


          • Jochen Weiss

            Jochen Weiss - 2008-12-13

            OK, let me try to explain what I'm doing:
            Because I never written any Python code or have any experience with Qt, I have to practice.

            What I'm trying to do is to write a class, we can call it e.g. "SilverScreen" or whatever, This class shall manage everything that will be visible via the projecter. In my little application it is called myvideoplayer.py (but it still need some code cleanup)

            This class must have a simple interface  with methods like

            setScreen(self,int screen) #which monitor is used
            setText(self,int xpos,ypos,QText text,QFont font)
            playVideo(self, QRect rect,MediaSource mediasource)
            setImage(self, QRect rect, QImage image)

            something like that.

            I'm just doing a "proof of concept" how you can display e.g. text on top of a movie or an image, how to display multiple images and on top of it a text or a movie, etc.

            I have no idea if or how this can be realized with PyQt but I'm positiv it won't be that hard

        • Martin Zibricky

          Martin Zibricky - 2008-12-12

          I wasn't able to get transparent background.

          But I have an idea. What about trying to use classes QPainter and QPainterPath?

          You could have a look at exaples what are coming with pyqt. There are some examples in the folder 'painting'.

          • Jochen Weiss

            Jochen Weiss - 2008-12-15

            QPainter seems to be a good solution, but I have the problem that the video is always displayed on top of the Text. Does somebody know if there is a way to change that order ?

            Or might be QGLWidget a good approach for this ?

            • Martin Zibricky

              Martin Zibricky - 2008-12-15

              What about  Phonon.VideoWidget?

              you could get this object by invoking 

              player = Phonon.VideoPlayer()
              widget = player.videoWidget()

              That's just a suggestion.

              • Jochen Weiss

                Jochen Weiss - 2008-12-16

                Do you think it should work to create a QtGui.QDialog and add Widgets like Phonon.VideoWidget, QLabel, QPainter, etc. ? Could work ...
                But how can I say which one stays on top and what item has to be in the background ? Always the last one wins ?

                • Martin Zibricky

                  Martin Zibricky - 2008-12-16

                  I don't know. It just an idea.
                  By calling method 'videoWidget' at your videoplayer object you can get the widget where the video is displayed.

                  I tried displaying QLabel at the top of that videoWidget but the effect was the same. (black background)

                  Anyway, you could have a look at this site, where a guy tried implementing subtitle library on top of phonon:


                  I don't know if his work was accepted into the 'Dragon player' but I presume that you should be able find some other information. When the library for subtitles handling was integrated into that player, the source code of that player may be a good inspiration.



Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks