How to resize a QColorDialog

382 views Asked by At

Is it possible to resize a QColorDialog? I have been unable to get the window to resize appropriately. After the dialog is shown, it reverts to the default size.

An example:

import sys

from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *

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

        layout = QVBoxLayout()
        push_Button = QPushButton()
        layout.addWidget(push_Button)

        push_Button.clicked.connect(self.button)
        self.setLayout(layout)

    def button(self):
        color = QColorDialog(self)
        color.resize(100,100)
        print(color.size()) #Prints 100, 100
        color.show()
        print(color.size()) #Prints 551, 431

if __name__ == '__main__':

    app = QApplication(sys.argv)
    window = Window()
    window.show()
    sys.exit(app.exec_())
1

There are 1 answers

0
ekhumoro On BEST ANSWER

The QColorDialog has a fixed size, because it contains several custom widgets which aren't designed to be resizable. It is possble to override these constraints and allow for manual resizing like this:

    color = QColorDialog(self)
    color.setSizeGripEnabled(True)
    color.layout().setSizeConstraint(QLayout.SetNoConstraint)
    color.show()

However, as you will see, the layout quickly becomes messed up with even a little bit of resizing. I also found that beyond a certain point, the dialog will actually crash due to floating point exceptions. So I think you will either have to accept it as it is, or perhaps write your own color dialog.