Highlight text in list box
Hi....
I want to Hightlight the text in the list box when i receive a particular message.
i want to scroll the list box without using the up/ down arrow or without clicking on the list box . this is to be done when i get a message.
when i get a message which says Next , then i need to scroll up.
how do i do this??
how do i make a default selection in the List Box???
plz help, i need this urgent....
Re: Highlight text in list box
Re: Highlight text in list box
I am using QListView . will setCurrentItem() work for it?
Re: Highlight text in list box
Since you wrote 'list box' I thought you meant Qt3.
Since QListView doesn't have setCurrentItem() it wont work.
In Qt4 the model-view approach is used much more then in Qt3.
I didn't have a chance to wrok with it yet under Qt4 - but from what I have read so far, i think you should use the selction model.
QItemSelectionModel::select ()
And this might be helpful as well: http://doc.trolltech.com/4.2/model-view-selection.html
Re: Highlight text in list box
I did that the following way:
QListViewItem *current = listview->currentItem();
QListViewItem *after = current->itemAbove(); OR itemBelow()
after->setSelected(TRUE);
this way it is working.....i am able to highlight the next item in the list whenever i get a particular signal.
Re: Highlight text in list box
I guess my question fits this thread, but solution given in last post I think isn't apropriate for Qt4.
So, what exactly I want to do. I have a widget with QListView, QDirModel and QSelectionModel and actually I want the widget to remember activated directory, so when I come back cursor/highlighting will be on that directory.
Example:
we have following items in current dir:
. .. pics walls sample.png pict.jpg
What is default: Key_Down x 3 /*go to pics*/, Key_Return, ... , <go to "..">, enter, Key_Down x 4 /*go to walls*/, enter.
What I want: Key_Down x 3 /*go to pics*/, enter, ..., <go to "..">, enter, Key_Down x 1 /*go to walls*/, enter.
setCurrentIndex() doesn't work, it sets but doesn't highlight that. And you can then press Key_{Return,Enter} (btw are they equal? I know that they have different values, but anyway...) and activate it, but if you press Key_Down you will be at "."
How to solve the problem? I don't need the full code for this =) but just wanna know how to set position of List View cursor.
offtopic
How to get rid of "." item, but keep ".."? I know about QDir::NoDotAndDotDot, but what about QDir::NoDot ?
updated
Ok, found this in QListWidget::setItemSelected(const QListWidgetItem *item, bool select)
Code:
if (d->selectionMode == SingleSelection) {
selectionModel()->select(index, select
}
But when I come into /home/eruart/imgs code:
Code:
selmodel
->select
(dirmodel
->index
("/home/eruart/imgs/example.png"),
QItemSelectionModel::ClearAndSelect);
gives me following in console:
intersectingStaticSet: row 11 was invalid
intersectingStaticSet: row 12 was invalid
What does it mean?
update 2
Code:
if (!dirmodel->fileName(current).contains("..")) last = current;
qDebug() << last;
current here is const QModelIndex & that passed by listview's activated signal, and this code is handleActivated slot that connected with the signal.
Code:
intersectingStaticSet: row 11 was invalid
intersectingStaticSet: row 12 was invalid
~/imgs $ ls -a | wc
11 12 135
Why rows 11 and 12, but not 4?
Re: Highlight text in list box
And now I am completely confused. I have removed all selecting code and those messages with intersectingStaticSet continue to appear.
updated
Hm, I recompiled with Qt4.3beta (was 4.2.3) and those messages disappeared.
But selecting still doesn't work.
Re: Highlight text in list box
I'll answer by myself, in case if someone will need it. It's far from ideal, but works for me.
Code:
unsigned int lastrow;
kivBrowser::kivBrowser()
{
...
nameFilters << "??*" << ".." ;// FIX ME: one char length names doesn't match
dirmodel->setNameFilters(nameFilters);
...
}
void kivBrowser
::handleActivated(const QModelIndex & current
) {
if (dirmodel->isDir(current))
{
listview->setRootIndex(current);
listview->setCurrentIndex(listview->rootIndex().child(0,0));
if (!current.row()) // FIX ME: if we cd up but never was there we would select wrong item or fail to select at all.
{
QModelIndex last
= listview
->rootIndex
().
child(lastrow,
0);
listview->setCurrentIndex(last);
}
else lastrow = current.row();
emit dirChanged(dirmodel->filePath(current));
}
else
emit imgChanged(dirmodel->filePath(current));
}