Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Qt.FramelessWindowHint and WA_TranslucentBackground not working
Forum Updated to NodeBB v4.3 + New Features

Qt.FramelessWindowHint and WA_TranslucentBackground not working

Scheduled Pinned Locked Moved Unsolved Qt for Python
6 Posts 3 Posters 5.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.
  • D Offline
    D Offline
    DiGol
    wrote on last edited by
    #1
            self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
            self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
    

    Why does not it work?
    main.py

    from PyQt5.QtWidgets import QWidget, QApplication
    import  sys
    import platform
    from PyQt5 import uic
    from PyQt5 import QtGui, QtWidgets, QtCore
    from PyQt5.QtGui import (QBrush, QColor, QConicalGradient, QCursor, QFont, QFontDatabase, QIcon, QKeySequence, QLinearGradient, QPalette, QPainter, QPixmap)
    from PyQt5.QtCore import (QCoreApplication, QPropertyAnimation, QDate, QDateTime, QMetaObject, QObject, QPoint, QRect, QSize, QTime, QUrl, Qt, QEvent)
    from PyQt5.QtWidgets import *
    class SplashScreen(QMainWindow):
        def __init__(self):
            super().__init__()
            self.ui = uic.loadUi('ui.ui')
            self.progressBarValue(50)
            self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
            self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
            self.shadow = QGraphicsDropShadowEffect(self)
            self.shadow.setBlurRadius(20)
            self.shadow.setXOffset(0)
            self.shadow.setYOffset(0)
            self.shadow.setColor(QColor(0, 0, 0, 120))
            self.ui.circularBg.setGraphicsEffect(self.shadow)
            self.ui.show()
        def progressBarValue(self, value):
            styleSheet = '''
            QFrame{
                border-radius: 150px;
                background-color: qconicalgradient(cx:0.5, cy:0.5, angle:90, stop:{STOP_1} rgba(0, 0, 0, 0), stop:{STOP_2} rgba(85, 170, 255, 255));
            }
            '''
            progress = (100 - value) / 100.0
            stop_1 = str(progress - 0.001)
            stop_2 = str(progress)
            newStylesheet = styleSheet.replace('{STOP_1}', stop_1).replace('{STOP_2}', stop_2)
            self.ui.circularProgress.setStyleSheet(newStylesheet)
    if __name__ == '__main__':
        app = QApplication(sys.argv)
        ex = SplashScreen()
        sys.exit(app.exec_())
    

    ui.ui

    <?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
     <class>SplashScreen</class>
     <widget class="QMainWindow" name="SplashScreen">
      <property name="geometry">
       <rect>
        <x>0</x>
        <y>0</y>
        <width>340</width>
        <height>340</height>
       </rect>
      </property>
      <property name="windowTitle">
       <string>MainWindow</string>
      </property>
      <widget class="QWidget" name="centralwidget">
       <widget class="QFrame" name="circularPragressBarBase">
        <property name="geometry">
         <rect>
          <x>10</x>
          <y>10</y>
          <width>320</width>
          <height>320</height>
         </rect>
        </property>
        <property name="frameShape">
         <enum>QFrame::NoFrame</enum>
        </property>
        <property name="frameShadow">
         <enum>QFrame::Raised</enum>
        </property>
        <widget class="QFrame" name="circularProgress">
         <property name="geometry">
          <rect>
           <x>10</x>
           <y>10</y>
           <width>300</width>
           <height>300</height>
          </rect>
         </property>
         <property name="styleSheet">
          <string notr="true">QFrame{
    	border-radius: 150px;
    	background-color: qconicalgradient(cx:0.5, cy:0.5, angle:90, stop:0.749 rgba(0, 0, 0, 0), stop:0.75 rgba(85, 170, 255, 255));
    }</string>
         </property>
         <property name="frameShape">
          <enum>QFrame::NoFrame</enum>
         </property>
         <property name="frameShadow">
          <enum>QFrame::Raised</enum>
         </property>
        </widget>
        <widget class="QFrame" name="circularBg">
         <property name="geometry">
          <rect>
           <x>10</x>
           <y>10</y>
           <width>300</width>
           <height>300</height>
          </rect>
         </property>
         <property name="styleSheet">
          <string notr="true">QFrame{
    	border-radius: 150px;	
    	background-color: rgb(110, 77, 127, 120);
    }</string>
         </property>
         <property name="frameShape">
          <enum>QFrame::NoFrame</enum>
         </property>
         <property name="frameShadow">
          <enum>QFrame::Raised</enum>
         </property>
        </widget>
        <widget class="QFrame" name="container">
         <property name="geometry">
          <rect>
           <x>25</x>
           <y>25</y>
           <width>270</width>
           <height>270</height>
          </rect>
         </property>
         <property name="styleSheet">
          <string notr="true">QFrame{
    	border-radius: 135px;
    	background-color: rgb(110, 77, 127);
    }</string>
         </property>
         <property name="frameShape">
          <enum>QFrame::NoFrame</enum>
         </property>
         <property name="frameShadow">
          <enum>QFrame::Raised</enum>
         </property>
         <widget class="QWidget" name="layoutWidget">
          <property name="geometry">
           <rect>
            <x>60</x>
            <y>36</y>
            <width>156</width>
            <height>224</height>
           </rect>
          </property>
          <layout class="QGridLayout" name="gridLayout">
           <item row="5" column="0">
            <widget class="QLabel" name="labelCredits">
             <property name="font">
              <font>
               <family>Segoe UI</family>
               <pointsize>9</pointsize>
              </font>
             </property>
             <property name="styleSheet">
              <string notr="true">background-color: none;
    color: rgb(218, 155, 255);</string>
             </property>
             <property name="text">
              <string>by: Dima </string>
             </property>
             <property name="alignment">
              <set>Qt::AlignCenter</set>
             </property>
            </widget>
           </item>
           <item row="0" column="0">
            <widget class="QLabel" name="labelTitle">
             <property name="font">
              <font>
               <family>Segoe UI</family>
               <pointsize>14</pointsize>
              </font>
             </property>
             <property name="styleSheet">
              <string notr="true">background-color: none;
    color: rgb(255, 255, 255);</string>
             </property>
             <property name="text">
              <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;CONS-2 &lt;/span&gt;&lt;span style=&quot; color:#e3e0e0;&quot;&gt;beta 1&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
             </property>
             <property name="alignment">
              <set>Qt::AlignCenter</set>
             </property>
            </widget>
           </item>
           <item row="4" column="0">
            <widget class="QLabel" name="labelLoading">
             <property name="minimumSize">
              <size>
               <width>0</width>
               <height>20</height>
              </size>
             </property>
             <property name="maximumSize">
              <size>
               <width>16777215</width>
               <height>20</height>
              </size>
             </property>
             <property name="font">
              <font>
               <family>Segoe UI</family>
               <pointsize>9</pointsize>
              </font>
             </property>
             <property name="styleSheet">
              <string notr="true">QLabel{
    	border-radius: 10px;
    	color: rgb(255, 255, 255);
    	background-color: rgb(129, 91, 150);
    	margin-right: 20px;
    	margin-left: 20px;
    }</string>
             </property>
             <property name="text">
              <string>loading...</string>
             </property>
             <property name="alignment">
              <set>Qt::AlignCenter</set>
             </property>
            </widget>
           </item>
           <item row="3" column="0">
            <widget class="QLabel" name="labelPercentage">
             <property name="font">
              <font>
               <family>Yu Gothic UI Light</family>
               <pointsize>68</pointsize>
              </font>
             </property>
             <property name="styleSheet">
              <string notr="true">background-color: none;
    color: rgb(255, 255, 255);</string>
             </property>
             <property name="text">
              <string>&lt;p&gt;&lt;span style=&quot; font-size:56pt; color:#eeeeee;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot; font-size:46pt; color:#eeeeee; vertical-align:super;&quot;&gt;%&lt;/span&gt;</string>
             </property>
             <property name="alignment">
              <set>Qt::AlignCenter</set>
             </property>
            </widget>
           </item>
          </layout>
         </widget>
        </widget>
        <zorder>circularBg</zorder>
        <zorder>circularProgress</zorder>
        <zorder>container</zorder>
       </widget>
      </widget>
     </widget>
     <resources/>
     <connections/>
    </ui>
    
    
    1 Reply Last reply
    1
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What exactly does not work ?
      Are you using PySide2, PySide6, PyQt5 ?
      On which platform ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DiGol
        wrote on last edited by
        #3
        1. This does not work:
                self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
                self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
        
        1. I am using PyQt5
        2. Windows 10
        1 Reply Last reply
        0
        • ndiasN Offline
          ndiasN Offline
          ndias
          wrote on last edited by ndias
          #4

          Hi @DiGol ,

          Please use self.ui:

                  self.ui.setWindowFlags(QtCore.Qt.FramelessWindowHint)
                  self.ui.setAttribute(QtCore.Qt.WA_TranslucentBackground)
          

          Best Regards

          da856ca6-3c78-403f-9550-a389eee49063-image.png

          D 1 Reply Last reply
          1
          • ndiasN ndias

            Hi @DiGol ,

            Please use self.ui:

                    self.ui.setWindowFlags(QtCore.Qt.FramelessWindowHint)
                    self.ui.setAttribute(QtCore.Qt.WA_TranslucentBackground)
            

            Best Regards

            da856ca6-3c78-403f-9550-a389eee49063-image.png

            D Offline
            D Offline
            DiGol
            wrote on last edited by
            #5

            @ndias Thank you!!!

            ndiasN 1 Reply Last reply
            0
            • D DiGol

              @ndias Thank you!!!

              ndiasN Offline
              ndiasN Offline
              ndias
              wrote on last edited by
              #6

              @DiGol: Please mark this topic as solved.
              And for last, congratulations on the fantastic progress bar you have implemented 😉

              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