[PySide] Default buttons in modal dialogs

305 views
Skip to first unread message

Dietmar Schwertberger

unread,
Jan 23, 2011, 7:37:58 AM1/23/11
to pys...@lists.openbossa.org
Hi!

Somehow I can't manage to make a button to act as default button in a
dialog the way I want to.

I want to
- create the dialog
- show it as modal dialog with exec_()
- make it close when the user
- explicitely closes it or
- hits Enter or
- clicks one of the action buttons ('Find' in my case)
I've tried both setDefault() on the button and using QDialogButtonBox.

This is on my N900 with (1, 0, 0, 'beta', 3), but seems the same on
Windows 0.4.2.

E.g. on windows when I run
pyside-pyside-examples\examples\dialogs\extension.py
the Find button is highlighted as default button, but when I hit enter
or click the button, the dialog does not close.

The same happens with my code (below) on the N900.

The standard dialogs like QInputDialog.getText behave as expected.

Am I missing something?


Regards,

Dietmar


dlg = QtGui.QDialog(self)
lineEdit = QtGui.QLineEdit()
albumsCheckBox = QtGui.QCheckBox("&Albums/Folders")
albumsCheckBox.setChecked(True)
tracksCheckBox = QtGui.QCheckBox("&Tracks/Titles")
samplerCheckBox = QtGui.QCheckBox("&Include Samplers")
findButton = QtGui.QPushButton("&Find", dlg)
#findButton.setDefault(True)
bb = QtGui.QDialogButtonBox(orientation=Qt.Vertical, parent=dlg)
bb.addButton(findButton, QtGui.QDialogButtonBox.ActionRole)
#bb.addButton(self.quitButton, QtGui.QDialogButtonBox.RejectRole)

leftLayout = QtGui.QVBoxLayout()
leftLayout.addWidget(lineEdit)
leftLayout.addWidget(albumsCheckBox)
leftLayout.addWidget(tracksCheckBox)
leftLayout.addWidget(samplerCheckBox)
#leftLayout.addStretch(1)
#mainLayout = QtGui.QGridLayout()
mainLayout = QtGui.QHBoxLayout()
mainLayout.addLayout(leftLayout)
#mainLayout.addWidget(findButton)
mainLayout.addWidget(bb)
dlg.setLayout(mainLayout)
dlg.setWindowTitle("Search")
findButton.setDefault(True)
res = dlg.exec_()

_______________________________________________
PySide mailing list
PyS...@lists.openbossa.org
http://lists.openbossa.org/listinfo/pyside

Dietmar Schwertberger

unread,
Jan 28, 2011, 2:08:23 PM1/28/11
to pys...@lists.openbossa.org
Am 23.01.2011 13:37, schrieb Dietmar Schwertberger:
> Somehow I can't manage to make a button to act as default button in a
> dialog the way I want to.

> E.g. on windows when I run


> pyside-pyside-examples\examples\dialogs\extension.py
> the Find button is highlighted as default button, but when I hit enter
> or click the button, the dialog does not close.

OK, no reply - maybe I should have asked the question in a different way:
I consider this behaviour a bug. But as it is such a basic functionality
I could not imagine that such a bug would not have been discovered
before...


Regards,

Dietmar

Hugo Parente Lima

unread,
Jan 28, 2011, 2:48:38 PM1/28/11
to pys...@lists.openbossa.org
On Friday 28 January 2011 17:08:23 Dietmar Schwertberger wrote:
> Am 23.01.2011 13:37, schrieb Dietmar Schwertberger:
> > Somehow I can't manage to make a button to act as default button in a
> > dialog the way I want to.
> >
> > E.g. on windows when I run
> > pyside-pyside-examples\examples\dialogs\extension.py
> > the Find button is highlighted as default button, but when I hit enter
> > or click the button, the dialog does not close.
>
> OK, no reply - maybe I should have asked the question in a different way:
> I consider this behaviour a bug. But as it is such a basic functionality
> I could not imagine that such a bug would not have been discovered
> before...

Why it's a bug, It work the way you want to on C++ or PyQt4?

--
Hugo Parente Lima
INdT - Instituto Nokia de Tecnologia

signature.asc

Dietmar Schwertberger

unread,
Jan 28, 2011, 6:17:46 PM1/28/11
to Hugo Parente Lima, pys...@lists.openbossa.org
Am 28.01.2011 20:48, schrieb Hugo Parente Lima:
> On Friday 28 January 2011 17:08:23 Dietmar Schwertberger wrote:
>> Am 23.01.2011 13:37, schrieb Dietmar Schwertberger:
>>> Somehow I can't manage to make a button to act as default button in a
>>> dialog the way I want to.

> Why it's a bug, It work the way you want to on C++ or PyQt4?

OK, after trying with PyQt, I found the reason.

I did not expect that I need to connect the default button to the accept
method myself:
findButton.clicked.connect(dlg.accept)
On all other platforms that I have been using, this is the default
behaviour for modal dialogs...

Reply all
Reply to author
Forward
0 new messages