I am trying to make a picture editor where you can choose your color on the right side and edit the picture on the left side of your screen. So I need a QHBoxLayout to set my two windows side by side. I can't add my ColorDialog to the QHBoxLayout. For test purpose I used a button instead of the picture.
I tired to add the ColorDialog with .addWidget but it didn't work. The ColorDialog is still shown but without the button on the side.
def initUI(self):
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
color = QColorDialog.getColor()
horizontalbox = QHBoxLayout
cancelbutton = QPushButton("CancelButton")
horizontalbox.addWidget(cancelbutton)
horizontalbox.addWidget(color)
self.setLayout(horizontalbox)
self.show()
QColorDialog.getColor() is a static method only returns a selected QColor does not allow to obtain the widget so you should not use that method but you must create an object of the class QColorDialog as I show below.
Update:
QColorDialog is a dialog window whose predefined behavior is to close the window, so a possible solution is to disconnect the clicked signal from the button, and to get the color after pressing you must use the clicked signal connected to another slot. I also see the cancel button of the QColorDialog unnecessary because of what I have hidden.