[Python] PySide6 QColorDialog Inner Layout Size

Discussão em 'Python' iniciado por Stack, Setembro 24, 2024.

  1. Stack

    Stack Membro Participativo

    Whenever I open the QColorDialog, the values in spinbuttons (Right Bottom) are not shown properly.

    [​IMG]


    • Python version : 3.12.4


    • PySide6 Version : 6.7.2

    [ Test Code ]

    from PySide6.QtWidgets import QApplication, QLayout, QWidget, QGridLayout, QPushButton, QColorDialog
    from PySide6.QtGui import QColor
    import sys

    class myWidget(QWidget):
    def __init__(self):
    super().__init__()

    layout = QGridLayout()

    self.button = QPushButton("Color")
    self.button.clicked.connect(self.set_button_color)

    layout.addWidget(self.button)

    self.setLayout(layout)

    self.setWindowTitle("Test")
    self.show()

    def set_button_color(self):
    dialog = QColorDialog()
    dialog.setSizeGripEnabled(True)
    dialog.layout().setSizeConstraint(QLayout.SetNoConstraint)

    color = dialog.getColor()

    if QColor.isValid(color):
    print("Selected Color Information:", color.name())
    self.button.setStyleSheet("background-color: %s;"%color.name())

    app = QApplication.instance()
    if not app:
    app = QApplication(sys.argv)
    myApp = myWidget()
    sys.exit(app.exec())

    Continue reading...

Compartilhe esta Página