Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-1350

can not create window win transparent background

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • P2: Important
    • None
    • 5.15.0
    • PySide
    • None
    • Kubuntu 20.04
    • Linux/X11

    Description

      I can not create a window with transparent background.

       

      Here is a minimal example that displays a circle (in Python):

       

      import sys
      from PyQt5.QtCore import Qt
      from PyQt5.QtGui import QPainter, QBrush
      from PyQt5.QtWidgets import QDialog, QApplicationWIDTH=400
      HEIGHT=400class MyWindow(QDialog):    def __init__(self):
              super().__init__()        self.setModal(True)
              self.setWindowOpacity(0.5)
              self.setStyleSheet('background: transparent; background-color: none; opacity: 0.5;')
              self.setAttribute(Qt.WA_TranslucentBackground, True)
              self.setWindowFlags(Qt.Window | Qt.WindowStaysOnTopHint | Qt.FramelessWindowHint)
              self.setAttribute(Qt.WA_NoSystemBackground, True)
              self.setAttribute(Qt.WA_OpaquePaintEvent, False)
              #self.setAttribute(Qt.WA_PaintOnScreen)        self.setMinimumWidth(WIDTH)
              self.setMinimumHeight(HEIGHT)
              self.setMaximumWidth(WIDTH)
              self.setMaximumHeight(HEIGHT)    def paintEvent(self, event):
              painter = QPainter(self)
              painter.setRenderHint(QPainter.Antialiasing)
              painter.setBrush(QBrush(Qt.gray, Qt.SolidPattern))
              painter.drawEllipse(0, 0, WIDTH, HEIGHT)def main():
          app = QApplication(sys.argv)
          win = MyWindow()
          win.show()
          sys.exit(app.exec_())
      

      As you can see I tried many things (setWindowOpacity, Qt.WA_NoSystemBackground, Qt.WA_OpaquePaintEvent, etc), but the black background is still visible.

       

      On my other other computer which runs Manjaro it works well, but not on my current, which runs Kubuntu 20.04. I tried both with PyQt 5.15 and 5.12 (the version used by KDE).

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            crmaurei Cristian Maureira-Fredes
            roipoussiere John Doe
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes