Re: [PyQt] QCheckBox problem

2009-01-08 Thread Ulrich Berning

Doug Hackworth wrote:



 FoobarApplication is calling the wrong super-class __init__.

Duly noted, thanks for the correction.  I changed it to call 
QtGui.QMainWindow.__init__() instead.  The change produced no visible 
effect, but I assume it's a better initialization to call, so thanks 
for pointing this out.




Use the stateChanged(int) signal instead.



That did the trick, thanks!  Question:  Was I wrong to use the 
toggled() signal and should have known to use stateChanged(int) 
instead?  What's the difference between the two?


The toggled signal is defined as: void QAbstractButton::toggled ( bool 
checked )
Use  QtCore.SIGNAL(toggled(bool)) instead of 
QtCore.SIGNAL(toggled()) and it will work as expected.
Because a QCheckBox can be a tri-state checkbox , it's better to use 
stateChanged(int) instead of toggled(bool).


Ulli

___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] QCheckBox problem

2009-01-05 Thread Doug Hackworth


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
#! /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 listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Re: [PyQt] QCheckBox problem

2009-01-05 Thread Doug Hackworth


 FoobarApplication is calling the wrong super-class __init__.

Duly noted, thanks for the correction.  I changed it to call 
QtGui.QMainWindow.__init__() instead.  The change produced no visible effect, 
but I assume it's a better initialization to call, so thanks for pointing this out.




Use the stateChanged(int) signal instead.


That did the trick, thanks!  Question:  Was I wrong to use the toggled() signal 
and should have known to use stateChanged(int) instead?  What's the difference 
between the two?


Thanks again,
Doug

___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


[PyQt] QCheckBox problem

2009-01-04 Thread Doug Hackworth


Greetings.  This should be an easy one for someone to answer.

Simple situation:  I have a QCheckBox on a main window along with other widgets, 
but mysteriously it won't do anything.  Since all my other widgets (buttons, 
mainly) do what they're supposed to, I suspect I am using the QCheckBox 
incorrectly.  It's the first time I've tried using one.


I am attempting to connect the checkbox's toggled() signal to a slot with this 
line:


code
QtCore.QObject.connect(self.ui.checkMyCheckbox, QtCore.SIGNAL(toggled()), 
self.MyCheckboxSlotFunction)

/code

Here is the slot I have defined for it:

code
def CheckMultiMask(self):
sys.stdout.write(checkbox toggleded\n)
if (self.ui.checkMyCheckbox.isChecked()):
sys.stdout.write(it's checked\n)
/code

When the window loads, however, I can click on the QCheckBox all I want, to no 
avail.  Also, the application object doesn't complain when it loads, and I know 
it's getting to the connect() invocation quoted above...  I just don't know why 
the slot function doesn't seem to ever be invoked.  And again, my other widgets 
with signals/slots connected by me (in a manner like that above) are behaving as 
expected.


Any thoughts from the experts?  I'll be happy to provide further information on 
context if it's useful.


BTW, I'm using Ubuntu 7.10 and the following versions of PyQt / Qt:
$ pyuic4 --version
Python User Interface Compiler 4.3 for Qt version 4.3.2

(The MainWindow was constructed with Qt Designer by way of pyuic4.)

Thanks,
Doug

___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] QCheckBox problem

2009-01-04 Thread Jim Bublitz
On Sunday 04 January 2009 17:30:41 pm Doug Hackworth wrote:
 Greetings.  This should be an easy one for someone to answer.

 Simple situation:  I have a QCheckBox on a main window along with
 other widgets, but mysteriously it won't do anything.  Since all my
 other widgets (buttons, mainly) do what they're supposed to, I
 suspect I am using the QCheckBox incorrectly.  It's the first time
 I've tried using one.

 I am attempting to connect the checkbox's toggled() signal to a
 slot with this line:

 code
 QtCore.QObject.connect(self.ui.checkMyCheckbox,
 QtCore.SIGNAL(toggled()), self.MyCheckboxSlotFunction)
 /code

 Here is the slot I have defined for it:

 code
 def CheckMultiMask(self):
  sys.stdout.write(checkbox toggleded\n)
  if (self.ui.checkMyCheckbox.isChecked()):
  sys.stdout.write(it's checked\n)
 /code

 When the window loads, however, I can click on the QCheckBox all I
 want, to no avail.  Also, the application object doesn't complain
 when it loads, and I know it's getting to the connect() invocation
 quoted above...  I just don't know why the slot function doesn't seem
 to ever be invoked.  And again, my other widgets with signals/slots
 connected by me (in a manner like that above) are behaving as
 expected.

 Any thoughts from the experts?  I'll be happy to provide further
 information on context if it's useful.

 BTW, I'm using Ubuntu 7.10 and the following versions of PyQt / Qt:
 $ pyuic4 --version
 Python User Interface Compiler 4.3 for Qt version 4.3.2

 (The MainWindow was constructed with Qt Designer by way of pyuic4.)

If the code you've provided is what you actually have, you haven't 
connected the signal to the slot you show - instead of 
self.MyCheckboxSlotFunction, you should be connecting to 
self.CheckMultiMask.

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.

Jim
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] QCheckBox problem

2009-01-04 Thread Hackworth, Doug

 If the code you've provided is what you actually have, you haven't
 connected the signal to the slot you show - instead of
 self.MyCheckboxSlotFunction, you should be connecting to
 self.CheckMultiMask.

Darn it.  Editing problem, not a coding problem.  I was renaming my
variables/functions to generic names for the purpose of illustrating my
problem to the mailing list, and missed one.  In the context of my
provided example, the slot function should really be:

def MyCheckboxSlotFunction(self):
(etc)

Sorry for the confusion.

 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.

Sure, I'll do that.  It will follow this message (perhaps not immediately).

Thanks,
Doug


___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt