Qt.FramelessWindowHint and WA_TranslucentBackground not working
Unsolved
Qt for Python
-
self.setWindowFlags(QtCore.Qt.FramelessWindowHint) self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
Why does not it work?
main.pyfrom 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><html><head/><body><p><span style=" font-weight:600;">CONS-2 </span><span style=" color:#e3e0e0;">beta 1</span></p></body></html></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><p><span style=" font-size:56pt; color:#eeeeee;">0</span><span style=" font-size:46pt; color:#eeeeee; vertical-align:super;">%</span></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>
-
Hi,
What exactly does not work ?
Are you using PySide2, PySide6, PyQt5 ?
On which platform ?