Reputation: 1300
I noticed a weird behavior when running a frameless widget in PyQt. If I minimize it in taskbar multiple times, a Windows XP title bar appears in the top left corner during a few milliseconds and then disappears.
Here is a simple code to reproduce the problem :
import sys
from PyQt5 import QtCore, QtWidgets
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
ui = QtWidgets.QWidget()
ui.setWindowFlags(ui.windowFlags() | QtCore.Qt.FramelessWindowHint)
ui.show()
sys.exit(app.exec_())
The behavior is described in this video
My setup is Windows 7 (x64), Python 3.5 and PyQt5.7 (FYI, the problem was also present in PyQt5.6)
Can anyone explain this behavior and give a solution ?
Upvotes: 1
Views: 960
Reputation: 43
If anyone still has problems with it:
Example:
class MainWindow(QtWidgets.QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.width = 400
self.height = 220
self.initUI()
def initUI(self):
self.setWindowFlags(Qt.FramelessWindowHint)
self.setFixedSize(self.width, self.height)
self.setAttribute(Qt.WA_TranslucentBackground)
self.window = QtWidgets.QWidget(self)
self.window.setStyleSheet("QWidget{background-color: #ffffff;}")
self.window.setGeometry(0, 0, self.width, self.height)
self.minimize_button = QtWidgets.QPushButton("🗕", self.window)
self.minimize_button.setGeometry(355, 2, 20, 20)
self.minimize_button.clicked.connect(self.minimize_window)
def minimize_window(self):
self.setWindowState(QtCore.Qt.WindowMinimized)
Now the title bar does not appear anymore, due to the window being invisible.
Upvotes: 1
Reputation: 1300
I reported the issue to Qt and it seems to be a general Windows bug :
Sergio Martins added a comment
I can reproduce this problem with a pure Windows example, (passing WS_VISIBLE | WS_POPUP | WS_SYSMENU | WS_MINIMIZEBOX to CreateWindowEx()). Doesn't seem fixable, other than removing the minimize button capability.
Upvotes: 2