Results 1 to 5 of 5

Thread: Navigate through qlistview items with shortcuts

  1. #1
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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:

    Qt Code:
    1. void informationDialog::keyPressEvent(QKeyEvent *event)
    2. {
    3. if (event->key() == Qt::Key_PageUp){
    4. emit previousTitle();
    5. }
    6. else if (event->key() == Qt::Key_PageDown){
    7. emit nextTitle();
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 

    and in mainDialog:

    Qt Code:
    1. void MainDialog::viewTitle(const QModelIndex& current)
    2. {
    3. if(!informationDialog) {
    4. informationDialog = new InformationDialog;
    5. connect(informationDialog, SIGNAL(previuosTitle()), this, SLOT(showPreviuosTitle()));
    6. connect(informationDialog, SIGNAL(nextTitle()), this, SLOT(showNextTitle()));
    7. }
    8. informationDialog->currentSelected(current);
    9. }
    To copy to clipboard, switch view to plain text mode 

    Which code I have to put in showPreviuosTitle()?

    Thanks
    Giuseppe CalÃ

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default 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?
    J-P Nurmi

  3. #3
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Navigate through qlistview items with shortcuts

    Quote Originally Posted by jpn View Post
    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
    Qt Code:
    1. select( const QModelIndex &, QItemSelectionModel::SelectionFlags )
    To copy to clipboard, switch view to plain text mode 
    which should work but i don't know how retrieve next/previous QModelIndex of the selected item.

    Regards
    Giuseppe CalÃ

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Navigate through qlistview items with shortcuts

    J-P Nurmi

  5. The following user says thank you to jpn for this useful post:

    jiveaxe (10th January 2008)

  6. #5
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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:

    Qt Code:
    1. void MainDialog::showPreviuosTitle()
    2. {
    3. QModelIndex mi = listView->currentIndex();
    4. if(mi.row() > 0) {
    5. listView->setCurrentIndex(mi.sibling(mi.row()-1,mi.column()));
    6. viewTitle(listView->currentIndex());
    7. }
    8. }
    9.  
    10. void MainDialog::showNextTitle()
    11. {
    12. QModelIndex mi = listView->currentIndex();
    13. if(mi.row() < listView->model()->rowCount() - 1) {
    14. listView->setCurrentIndex(mi.sibling(mi.row()+1,mi.column()));
    15. viewTitle(listView->currentIndex());
    16. }
    17. }
    To copy to clipboard, switch view to plain text mode 

    Thanks
    Giuseppe CalÃ

Similar Threads

  1. Items in QListView should sort on Header Click
    By vinnu in forum Qt Programming
    Replies: 14
    Last Post: 10th November 2006, 12:49
  2. moving Qlistview items
    By :db:sStrong in forum Qt Programming
    Replies: 0
    Last Post: 21st February 2006, 12:25

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.