After upgrading from PyQt 6.7 to 6.8, I noticed a strange thing in my app:
Some, not all, of the disabled QPushButtons
were blank (white and no text).
It took some time to figure out the conditions for this bug.
This was needed to reproduce:
- The OS theme must be dark
- The buttons need to be inside a
QSplitter
- The style must be
fusion
orwindowsvista
- (The style must be set after the initiation of the main window)
edit: Previously 'windows11' style must have been set.
A MRE:
from PyQt6.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout, QSplitter, QHBoxLayout, QLineEdit
from PyQt6.QtCore import Qt
class Main(QWidget):
def __init__(self):
super().__init__()
pb1 = QPushButton('pb1')
pb2 = QPushButton('pb2')
pb2.setEnabled(False)
pb1.clicked.connect(lambda: pb2.setDisabled(pb2.isEnabled()))
random_widget = QLineEdit()
btn_widg = QWidget()
btn_lay = QVBoxLayout(btn_widg)
btn_lay.addWidget(pb1)
btn_lay.addWidget(pb2)
tot_lay = QHBoxLayout(self)
# tot_lay.addWidget(random_widget)
# tot_lay.addWidget(btn_widg)
split = QSplitter(Qt.Orientation.Horizontal)
split.addWidget(random_widget)
split.addWidget(btn_widg)
tot_lay.addWidget(split)
app = QApplication([])
# app.setStyle('windows')
window = Main()
app.setStyle('fusion')
window.show()
app.exec()
And this is how it looks:
There's a simple workaround:
Setting any style before initiating the main window will show the disabled buttons normally, even if 'fusion' is set after that.
Maybe someone can test this on a non-windows OS.
Should this be reported to the Qt peoples?
and if so, how does one do that?
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744175924a4561753.html
评论列表(0条)