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
> 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
Why it's a bug, It work the way you want to on C++ or PyQt4?
--
Hugo Parente Lima
INdT - Instituto Nokia de Tecnologia
> 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...