10

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.

Ryan
  • 269
  • 1
  • 3
  • 15

2 Answers2

21

In python .-

self.buttonBox.button(QtGui.QDialogButtonBox.Reset).clicked.connect(foo)
xavi
  • 257
  • 1
  • 3
  • Perfect and how would I call the 'standard' reset function? – Ryan Jul 06 '13 at 14:19
  • I don't understand 'standard' reset function. ResetRole is an attribute. For example, if you want to connect buttons to a generic foo methodo. – xavi Jul 06 '13 at 17:56
  • 1
    i meant, the way, 'accept' role, successfully closes the dialog, does the 'reset' role clears the data fields? if yes, how would i assign the role? – Ryan Jul 07 '13 at 13:56
4

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.

thuga
  • 12,601
  • 42
  • 52