简体   繁体   中英

Pyside - QcolorDialog signals

What would be the signal for clicking the 'ok' button in the QColorDialog.

I tried

self.color_chooser = QtWidgets.QColorDialog()
self.color_chooser.getColor()
self.color_chooser.currentColorChanged.connect(self.color_pick)

def color_pick(self):
    print 'signaled'

that did not work.

The signal you are requesting is colorSelected , this is issued after pressing the OK button

class Widget(QWidget):
    def __init__(self, *args, **kwargs):
        QWidget.__init__(self, *args, **kwargs)
        self.color_chooser = QColorDialog()
        self.color_chooser.colorSelected.connect(self.color_pick)
        self.color_chooser.show()

    def color_pick(self, color):
        print('signaled', color)

If you want to get the color after pressing the OK button you can use these other methods:

class Widget(QWidget):
    def __init__(self, *args, **kwargs):
        QWidget.__init__(self, *args, **kwargs)
        self.color_chooser = QColorDialog()
        if self.color_chooser.exec_() == QColorDialog.Accepted:
            print(self.color_chooser.currentColor())

class Widget(QWidget):
    def __init__(self, *args, **kwargs):
        QWidget.__init__(self, *args, **kwargs)
        self.color_chooser = QColorDialog()
        color = self.color_chooser.getColor()
        if color.isValid():
            print(color, color.name())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM