Navigate through qlistview items with shortcuts
Hi and happy new year,
this is my problem:
my mainDialog has a qlistview. When I click on an item a modeless dialog is open showing some informations related to the item. What i want is that pressing, for example, PagDown it shows me informations on the next item of the qlistview (so having the focus on the informationDialog and without clicking on the item).
I have created this event:
Code:
void informationDialog
::keyPressEvent(QKeyEvent *event
) {
if (event->key() == Qt::Key_PageUp){
emit previousTitle();
}
else if (event->key() == Qt::Key_PageDown){
emit nextTitle();
}
}
and in mainDialog:
Code:
void MainDialog::viewTitle(const QModelIndex& current)
{
if(!informationDialog) {
informationDialog = new InformationDialog;
connect(informationDialog, SIGNAL(previuosTitle()), this, SLOT(showPreviuosTitle()));
connect(informationDialog, SIGNAL(nextTitle()), this, SLOT(showNextTitle()));
}
informationDialog->currentSelected(current);
}
Which code I have to put in showPreviuosTitle()?
Thanks
Re: Navigate through qlistview items with shortcuts
This forum doesn't work like "Hey, I need a function, could you guys code it for me?" so let's put it this way: what did you try so far?
Re: Navigate through qlistview items with shortcuts
Quote:
Originally Posted by
jpn
This forum doesn't work like "Hey, I need a function, could you guys code it for me?" so let's put it this way: what did you try so far?
I'm sorry if I give this impression, but the problem is that I haven't found in the documentation an hypothetically QListViewItemIterator (as in qt3); there is a QListIterator but it not seems usable in my case. My listview is using as model a QSqlTableModel but i have not found in its documentation an iterator or so.
Searching in the forum I have found this discussion, but QItemSelectionModel has
which should work but i don't know how retrieve next/previous QModelIndex of the selected item.
Regards
Re: Navigate through qlistview items with shortcuts
Re: Navigate through qlistview items with shortcuts
Thanks jpn, sibling was what I need (I'm italian so sometimes i don't understand the use of a function from its name: I had no idea of what was simling; after you pointed me to it I have recovered a thesaurus to get the meaning of that word and discovered that it was the function I was searching for).
Now the final code:
Code:
void MainDialog::showPreviuosTitle()
{
if(mi.row() > 0) {
listView->setCurrentIndex(mi.sibling(mi.row()-1,mi.column()));
viewTitle(listView->currentIndex());
}
}
void MainDialog::showNextTitle()
{
if(mi.row() < listView->model()->rowCount() - 1) {
listView->setCurrentIndex(mi.sibling(mi.row()+1,mi.column()));
viewTitle(listView->currentIndex());
}
}
Thanks