python - PyQt 6.8 blank button bug? - Stack Overflow

After upgrading from PyQt 6.7 to 6.8, I noticed a strange thing in my app:Some, not all, of the disabl

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 or windowsvista
  • (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

相关推荐

  • python - PyQt 6.8 blank button bug? - Stack Overflow

    After upgrading from PyQt 6.7 to 6.8, I noticed a strange thing in my app:Some, not all, of the disabl

    9天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信