[PyQt] Problems with QDialog, QLineEdit and returnPressed event

Mark Summerfield mark at qtrac.eu
Wed Oct 10 13:34:44 BST 2007


On 2007-10-10, duncan duncan wrote:
> Hello
>
> I am trying to have a QDialog (the gui was designed with QtDesigner) with
> some QLineEdit widget.
> The QLineEdit widget is connected to the returnPressed event.
>
> All work fine but when I press the Return key the dialog close.
> At this point find that the buttons on the dialog need to have the
> autoDefault property set to False.
>
> The dialog has a QDialogButtonBox for the two buttons (Ok and Cancel), and
> these buttons still have the
> autoDefault property set to True but I am not able to set it to False.
>
> I try with QtDesigner but all I see is the QDialogButtonBox widget, no
> access to the buttons, so I try with this code:
>
> ---
> for btn in self.uid.buttonBox.buttons():
>             btn.setAutoDefault(False)
> ---

try something like this (untested):

    self.uid.buttonBox.button(QDialogButtonBox.Ok).setAutoDefault(False)
    self.uid.buttonBox.button(QDialogButtonBox.Cancel).setAutoDefault(False)

>
> and this fail too.
>
> How can I solve the problem ? For now I have a workaround: I delete the
> QDialogButtonBox and use just to buttons
> connected with the accept() and reject() signal and this work.
>
> As a side note: I understand it correctly that if I need some input
> (QLineEdit specifically) connected wiht the returnPressed signal
> it is better to create a void dialog and then put all the controls than to
> create a dialog with the standard buttons ?
>
> Thanks
> bye
> Gianluca



-- 
Mark Summerfield, Qtrac Ltd., www.qtrac.eu



More information about the PyQt mailing list