I created a very basic example dialog with 2 qpushbuttons.  I set default
to true on one of them and I set autodefault to false on both of them.  I
then used pyuic4 to convert the .ui to a .py file and made a very simple
wrapper to connect simple functions to both button's click events.

The expected behavior is that pressing enter should fire the default
button's clicked handler no matter which button is currently focused, but
I'm not getting that behavior.  The default button is not getting clicked
if i have the other button selected and I press enter.

I tried building the same example in qt/c++ and I didn't have this issue.
Can anyone tell me if I'm doing something wrong.  I've attached all 3 files
I mentioned above.

-- 
-Zev

Attachment: untitled.ui
Description: application/designer

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'untitled.ui'
#
# Created: Sun Nov  6 14:31:14 2011
#      by: PyQt4 UI code generator 4.8.6
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    _fromUtf8 = lambda s: s

class Ui_Dialog(object):
    def setupUi(self, Dialog):
        Dialog.setObjectName(_fromUtf8("Dialog"))
        Dialog.resize(400, 300)
        Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "Dialog", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton = QtGui.QPushButton(Dialog)
        self.pushButton.setGeometry(QtCore.QRect(60, 170, 97, 27))
        self.pushButton.setText(QtGui.QApplication.translate("Dialog", "PushButton", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton.setAutoDefault(False)
        self.pushButton.setObjectName(_fromUtf8("pushButton"))
        self.defaultPushButton = QtGui.QPushButton(Dialog)
        self.defaultPushButton.setGeometry(QtCore.QRect(240, 170, 141, 27))
        self.defaultPushButton.setText(QtGui.QApplication.translate("Dialog", "DefaultPushButton", None, QtGui.QApplication.UnicodeUTF8))
        self.defaultPushButton.setAutoDefault(False)
        self.defaultPushButton.setDefault(True)
        self.defaultPushButton.setObjectName(_fromUtf8("defaultPushButton"))

        self.retranslateUi(Dialog)
        QtCore.QMetaObject.connectSlotsByName(Dialog)

    def retranslateUi(self, Dialog):
        pass

#!/usr/bin/python -d
 
import sys
from os.path import expanduser,  isdir
from PyQt4 import QtCore, QtGui
from PyQt4.QtGui import *
from PyQt4.QtCore import * 
from untitled import Ui_Dialog
 
class MyForm(QtGui.QMainWindow):
	curDir = None
    
	def __init__(self, parent=None):
		QtGui.QWidget.__init__(self, parent)
		self.ui = Ui_Dialog()
		self.ui.setupUi(self)
		QtCore.QObject.connect(self.ui.defaultPushButton, QtCore.SIGNAL("clicked()"), self.defaultClicked )
		QtCore.QObject.connect(self.ui.pushButton, QtCore.SIGNAL("clicked()"), self.checkDefaults )

	def defaultClicked(self):
		print("Default button clicked")
	
	def checkDefaults(self):
		print("Default button's isDefault setting is: "+str(self.ui.defaultPushButton.isDefault()))

if __name__ == "__main__":
	app = QtGui.QApplication(sys.argv)
	myapp = MyForm()
	myapp.show()
	sys.exit(app.exec_())
_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to