hi.

the attached code doesn't work as excepted. it should map the combobox-selection to the model, but it does not.

i'm using QDataWidgetMapper with other widgets without problems, only the QComboBox don't want to be mapped.

maybe i got something wrong, maybe it's a bug in pyqt or in qt.

nevertheless, any ideas?

cheers,

alexander
from PyQt4 import QtCore, QtGui

class MyWindow(QtGui.QMainWindow):
    def __init__(self):
        QtGui.QMainWindow.__init__(self)
        self.cb = QtGui.QComboBox(self)
        self.setCentralWidget(self.cb)
        self.cb.addItem("a bla", QtCore.QVariant("a"))
        self.cb.addItem("b bla", QtCore.QVariant("b"))
        self.cb.addItem("c bla", QtCore.QVariant("c"))
        self.cb.addItem("d bla", QtCore.QVariant("d"))
        self.cb.addItem("e bla", QtCore.QVariant("e"))

        self.model = QtGui.QStandardItemModel(1, 1, self)
        self.dwm = QtGui.QDataWidgetMapper(self)
        self.dwm.setModel(self.model)
        self.dwm.addMapping(self.cb, 0)

        self.connect(self.cb, QtCore.SIGNAL("currentIndexChanged(int)"), 
                     self.cbChanged)

        self.connect(self.dwm, QtCore.SIGNAL("currentIndexChanged(int)"), 
                     self.dwmChanged)

        self.dwm.toFirst()

    def cbChanged(self, i):
        mi = self.model.index(0, 0)
        print "cbChanged, data: '%s', index: %i" %  (mi.data().toString(), i )

    def dwmChanged(self, i):
        mi = self.model.index(0, 0)
        print "dwmChanged, data: '%s', index: %i" %  (mi.data().toString(), i )

if __name__ == '__main__':
    import sys
    app = QtGui.QApplication(sys.argv)
    a = MyWindow()
    a.show()
    app.exec_()
_______________________________________________
PyKDE mailing list    [email protected]
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde

Reply via email to