Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting a slot to a button in QDialogButtonBox

I created a standard buttonBox from QtDesigner with 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 would I connect the reset button to say function "foo()". I really have no idea. I read the docs about assigning roles and stuff, and its confusing.

Thanks in advance.

like image 681
Ryan Avatar asked Jul 03 '13 15:07

Ryan


2 Answers

In python .-

self.buttonBox.button(QtGui.QDialogButtonBox.Reset).clicked.connect(foo)
like image 106
xavi Avatar answered Sep 28 '22 00:09

xavi


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

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

This of course requires that you set the role for your reset button to QDialogButtonBox::Reset

Using the button function you can get your reset button and connect it to your slot. This is the list of roles your buttons can have. I hope this helps.

like image 39
thuga Avatar answered Sep 28 '22 00:09

thuga