[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: Re: [PyQt] QCheckBox problem
From: Doug Hackworth <doug.hackworth () vanderbilt ! edu>
Date: 2009-01-05 17:57:16
Message-ID: 496249FC.7010900 () vanderbilt ! edu
[Download RAW message or body]
> If that isn't the problem, it'd help someone to figure it out if you
> could provide a complete small executable program that exhibits the
> problem behavior.
Attached is an example program which illustrates the problem I'm having. Again,
the QCheckBox seems to work (its isChecked() method returns the correct thing,
for example), but there is no action from the slot function that I have
(ostensibly) connected to its toggled() signal.
I'm not a Qt or PyQt expert yet, so perhaps I've overlooked something
elementary. Any insights from this list's collected wisdome would be quite welcome.
Many thanks,
Doug
["Foobar.py" (text/x-python)]
#! /usr/bin/python
import sys
from PyQt4 import QtCore, QtGui
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(QtCore.QSize(QtCore.QRect(0,0,433,181).size()).expandedTo(MainWindow.minimumSizeHint()))
MainWindow.setBaseSize(QtCore.QSize(0,0))
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.buttonSubmit = QtGui.QPushButton(self.centralwidget)
self.buttonSubmit.setGeometry(QtCore.QRect(210,120,101,27))
self.buttonSubmit.setObjectName("buttonSubmit")
self.buttonQuit = QtGui.QPushButton(self.centralwidget)
self.buttonQuit.setGeometry(QtCore.QRect(330,120,80,27))
self.buttonQuit.setObjectName("buttonQuit")
self.textFilename = QtGui.QLineEdit(self.centralwidget)
self.textFilename.setEnabled(False)
self.textFilename.setGeometry(QtCore.QRect(30,70,340,29))
self.textFilename.setObjectName("textFilename")
self.checkAddFile = QtGui.QCheckBox(self.centralwidget)
self.checkAddFile.setGeometry(QtCore.QRect(30,30,251,23))
self.checkAddFile.setObjectName("checkAddFile")
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtGui.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QObject.connect(self.buttonQuit,QtCore.SIGNAL("clicked()"),MainWindow.close)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", \
"foobar", None, QtGui.QApplication.UnicodeUTF8))
self.buttonSubmit.setText(QtGui.QApplication.translate("MainWindow", "Do \
Things", None, QtGui.QApplication.UnicodeUTF8))
self.buttonQuit.setText(QtGui.QApplication.translate("MainWindow", "Quit", \
None, QtGui.QApplication.UnicodeUTF8))
self.checkAddFile.setText(QtGui.QApplication.translate("MainWindow", "This is \
a checkbox:", None, QtGui.QApplication.UnicodeUTF8))
class FoobarApplication(QtGui.QMainWindow):
def __init__(self, parent=None):
# Set up the GUI from the Qt Designer code...
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
# Connect signals and slots...
# Submit button
QtCore.QObject.connect(self.ui.buttonSubmit, QtCore.SIGNAL("clicked()"), \
self.Submit)
# Checkbox
QtCore.QObject.connect(self.ui.checkAddFile, QtCore.SIGNAL("toggled()"), \
self.CheckMultiMask)
# Slot for Submit button
def Submit(self):
filename = str(self.ui.textFilename.text())
fAddFile = self.ui.checkAddFile.isChecked()
sys.stdout.write('%s ... %s \n' % (fAddFile, filename))
# Slot for checkbox
def CheckMultiMask(self):
sys.stdout.write("multimask toggleded\n")
if (self.ui.checkMultiMask.isChecked()):
sys.stdout.write("it's checked\n")
self.ui.textFilename.setEnabled(True)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = FoobarApplication()
myapp.show()
sys.exit(app.exec_())
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic