Connecting a slot to a button in a QDialogButtonBox

I created a standard ButtonBox from QtDesigner using Ok, Cancel, Reset.

I successfully connected the Ok and Cancel buttons using

self.buttonBox.accepted.connect(self.accept) self.buttonBox.rejected.connect(self.reject) 

even defining my own accept function.

So how can I connect the reset button to say the function "foo ()". I really have no idea. I read role assignment docs, etc. And his confusion.

Thanks in advance.

+4
source share
2 answers

In python.-

 self.buttonBox.button(QtGui.QDialogButtonBox.Reset).clicked.connect(foo) 
+11
source

I don't know python, but how could you do this in C ++, it’s something like this:

 QPushButton *resetButton = ui->buttonBox->button(QDialogButtonBox::Reset); connect(resetButton, signal(clicked()), this, SLOT(myResetFunc())); 

This, of course, requires you to set the QDialogButtonBox::Reset role to your reset button.

Using button , you can get your reset button and connect it to your slot. This is a list of roles that your buttons may have. Hope this helps.

+1
source

Source: https://habr.com/ru/post/1489523/


All Articles