I've discovered that if I remove all flags from a QDialog
, and set Windows flags to QtCore.Qt.CustomizeWindowHint
and QtCore.Qt.WindowTitleHint
, the icon disappears, but also the close button. Unfortunately, if I add the flag of QtCore.Qt.WindowCloseButtonHint
, the icon returns.
Is there a way that I can add a close button to the window without having the icon?
Here is my code:
from PyQt5 import QtGui, QtCore
from PyQt5.QtWidgets import *
class MainWindow(QDialog):
def __init__(self):
super().__init__()
pixmap = QtGui.QPixmap(1, 1)
pixmap.fill(QtCore.Qt.transparent)
self.title_bar = "Graph Filter"
self.graph_icon = QtGui.QIcon("views/resources/icons/hexagon.png")
self.empty_icon = QtGui.QIcon(pixmap)
self.width = 600
self.height = 600
rectangle = self.frameGeometry()
center_point = QDesktopWidget().availableGeometry().center()
rectangle.moveCenter(center_point)
self.move(rectangle.topLeft())
self.init_window()
def init_window(self):
self.setWindowIcon(self.empty_icon)
self.setWindowTitle(self.title_bar)
self.setFixedSize(self.width, self.height)
self.setWindowFlags(QtCore.Qt.CustomizeWindowHint | QtCore.Qt.WindowTitleHint)
here there's no icon, but no close button:
here there is an icon space, but no close button:
The ideal world is to have no icon and a close button.
As you can see in the images, a transparent icon is not good either, because the space remains there.
Try it
windowflags.py
: