[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] QDataWidgetMapper
From:       Sibylle Koczian <Sibylle.Koczian () t-online ! de>
Date:       2007-11-27 20:47:35
Message-ID: 200711272147.35462.Sibylle.Koczian () t-online ! de
[Download RAW message or body]

Am Dienstag, 27. November 2007 20:02:51 schrieb Sibylle Koczian:
>
> I'm just playing with the QDataWidgetMapper myself, so I looked at your
> project and tried some changes. Changing the model to a QStandardItemModel,
> QSqlQueryModel, QSqlTableModel (with a SQLite memory "database") didn't
> help. But if I take the combobox out, then the QLineEdit shows content.
>
Wrong. I had added errors of my own. The problem _does_ lie in your model, 
only I can't find it there. 

> In my own project I've got a main window containing a QTableView and a
> QDialog containing only QLineEdit controls using a QDataWidgetMapper. That
> works.
>
> Could it be that you can't mix controls using a model directly and controls
> using a QDataWidgetMapper in the same window? Looks very strange.
>
No, it's not that. If you replace your dwm.py with the following, only 
slightly longer class definition, the QLineEdit shows the right content and 
this content follows changes in the QComboBox.

-----------------------------------------------------------------------------
from PyQt4 import QtGui, QtCore

from ui_dwm import Ui_Dwm

# from mymodel import MyModel
import mymodel

class Dwm(QtGui.QMainWindow):
    def __init__(self):
        QtGui.QMainWindow.__init__(self)

        self.ui = Ui_Dwm()
        self.ui.setupUi(self)

#       self.model = mymodel.MyModel()
        # new, koc
        self.model = self.makeModel()
        self.ui.comboBox.setModel(self.model)

        self.dwm = QtGui.QDataWidgetMapper()
        self.dwm.setModel(self.model)
        self.dwm.addMapping(self.ui.lineEdit, 1)
        self.dwm.toFirst()
        # new, koc
        self.connect(self.ui.comboBox, 
QtCore.SIGNAL("currentIndexChanged(int)"), 
                     self.dwm, QtCore.SLOT("setCurrentIndex(int)"))
        
    
    # new, koc
    def makeModel(self):
            model = QtGui.QStandardItemModel()
            for word in mymodel.words:
                ll = []
                ll.append(QtGui.QStandardItem(word['name']))
                ll.append(QtGui.QStandardItem(word['opposite']))
                model.appendRow(ll)
            return model
-----------------------------------------------------------------------------

This just replaces your model with a QStandardItemModell filled with the same 
data. Which most probably isn't what you really need. But I really can't see 
what's wrong with your model (some quite trivial corrections excepted, which 
didn't help).        

-- 
Dr. Sibylle Koczian
_______________________________________________
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