[PyKDE] QDialog and multiple buttons

Roberto Alsina ralsina at kde.org
Tue Aug 2 16:03:26 BST 2005


> Hi,
>
> I would like to create a dialog with three buttons: 'Heads', 'Tails',
> and 'Cancel'. If I only had the 'Heads' and 'Tails' buttons then my
> life would be easy. I would just connect the 'Heads' button up to the
> accept() slot and connect the 'Tails' button up to the reject() slot.
> What do I do with the 'Cancel' button? Is there a way to detect which
> button was clicked and modify the result so exec_loop() returns
> something other than Accepted or Rejected? Is there a better way of
> doing this?

Create a heads slot, and a tails slot.

def heads(self):
    self.head=True
    self.accept()

def tails(self):
    self.head=False
    self.accept()

When you exec_loop the dialog, first test what it returns, then use
dialog.head

It's a bit longer, but it is way cleaner, because you are not overloading
cancel(), which should mean "do nothing" with a meaning it doesn't usually
have.

Another idea is to use radio buttons showing head/tails and then use
regular accept/cancel buttons.

-- 
 ("\''/").__..-''"`-. .         Roberto Alsina
 `9_ 9  )   `-. (    ).`-._.`)  ralsina at kde.org
 (_Y_.)' ._   ) `._`.  " -.-'   KDE Developer (MFCH)
  _..`-'_..-_/ /-'_.'
(l)-'' ((i).' ((!.'             Buenos Aires - Argentina
Imminentizing the eschaton since 1971.




More information about the PyQt mailing list