[Qt-interest] small QDataWidgetMapper/QSelectionModel annoyance
Israel Brewster
israel at frontierflying.com
Tue Mar 3 20:36:25 CET 2009
I have an interface set up with two panes: a QListView on one side,
and a QTextEdit on the other. I am using a QDataWidgetMapper to map a
Model field to the QTextEdit, the QListView simply displays one of the
model columns (same model). In order to update the QDataWidgetMapper
(and, thus, the QTextEdit) when an item in the QListView is chosen, I
have the following code:
QItemSelectionModel *selectedNote=notesList->selectionModel();
connect
(selectedNote
,SIGNAL
(currentChanged
(QModelIndex
,QModelIndex)),¬eMapper,SLOT(setCurrentModelIndex(QModelIndex)));
this all works properly (noteMapper is my QDataWidgetMapper). The
problem I am running into is with the intial state. I want it to start
up with nothing selected in the QListView, and the QTextEdit being
empty (i.e. QDataWidgetMapper::currentIndex()==-1) So as the last line
of my constructor I put in:
selectedNote->setCurrentIndex(QModelIndex(),QItemSelectionModel::Clear);
and then checked in the debugger that everything was populated as
desired. This also worked. HOWEVER, upon the window being shown, I
found the following:
1) nothing selected in the list view (good)
2) the QTextEdit populated with the first item (bad)
3) the QSelectionModel positioned with the current index being the
first item of the QListView, as indicated by the fact the
currentChanged signal is not emitted when clicking the first item in
the QListView (bad)
Number two and three would imply (to me at least) that somehow the
currentChanged signal of the selectionModel was emitted AFTER the
constructor ran, with the currentIndex being set to the first item in
the QListView - probably when I called show(). This is not the
behavior I want. How can I either a) prevent the signal from being
emitted (if this is, in fact, what is going on) or b) reset everything
as the final action? I suppose I could kludge the second option
together by making a public "reset" function that I could call after
calling show, but that is kludgier than I would like if I could avoid
it. Thanks.
-----------------------------------------------
Israel Brewster
Computer Support Technician
Frontier Flying Service Inc.
5245 Airport Industrial Rd
Fairbanks, AK 99709
(907) 450-7250 x293
-----------------------------------------------
More information about the Qt-interest-old
mailing list