Ryan
Ryan

Reputation: 289

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.

Upvotes: 12

Views: 19533

Answers (2)

xavi
xavi

Reputation: 287

In python .-

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

Upvotes: 24

thuga
thuga

Reputation: 12931

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.

Upvotes: 6

Related Questions