Results 1 to 5 of 5

Thread: how to use listView enevt

  1. #1
    Join Date
    Apr 2009
    Posts
    35
    Thanks
    9
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Android

    Default how to use listView enevt

    i use a listView
    i select one line, is there have any event ?
    if selection changed , is it can emit any event ?
    how to use it ?

    i find i function

    Qt Code:
    1. void QAbstractItemView::selectionChanged ( const QItemSelection & selected, const QItemSelection & deselected ) [virtual protected slot]
    To copy to clipboard, switch view to plain text mode 

    This slot is called when the selection is changed. The previous selection (which may be empty), is specified by deselected, and the new selection by selected.

    See also setSelection().

    but, it's don't work..

    my code

    Qt Code:
    1. void MusicSettingsWidget::selectionChanged ( const QItemSelection & selected, const QItemSelection & deselected )
    2. {
    3. qDebug()<<"selection changed !";
    4. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by tsuibin; 15th October 2009 at 06:54.

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to use listView enevt

    what do you want to achieve?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: how to use listView enevt

    you can use QItemSelectionModel which you can get pointer to with
    Qt Code:
    1. QItemSelectionModel * QAbstractItemView::selectionModel () const
    To copy to clipboard, switch view to plain text mode 

    Edit:
    Ok I checked and for me that slot:
    Qt Code:
    1. void QAbstractItemView::selectionChanged ( const QItemSelection & selected, const QItemSelection & deselected ) [virtual protected slot]
    To copy to clipboard, switch view to plain text mode 
    in my view inherited from QListView is working fine. Is your MusicSettingsWidget derived from any view class (QAbstractItemView, QListView etc)?
    Last edited by faldzip; 15th October 2009 at 07:45.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  4. The following user says thank you to faldzip for this useful post:

    tsuibin (15th October 2009)

  5. #4
    Join Date
    Apr 2009
    Posts
    35
    Thanks
    9
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Android

    Default Re: how to use listView enevt

    I have solved this problem, qt has a clicked signal function that emitted when a mouse button is clicked. The item the mouse was clicked on is specified by index. The signal is only emitted when the index is valid.

    Qt Code:
    1. connect(ui->listView_Group,SIGNAL(clicked(const QModelIndex &)),this,SLOT(selectionChanged(const QModelIndex &)));
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. void MusicSettingsWidget::selectionChanged(const QModelIndex & index)
    2. {
    3. if ( index.data().toString() != "all music" ){
    4. musicSettings4a6ConfigFile->beginGroup("GroupList");
    5. QStringList musicList;
    6. musicList << musicSettings4a6ConfigFile->value(index.data().toString()).toString().split(";",QString::SkipEmptyParts);
    7. musicSettings4a6ConfigFile->endGroup();
    8. mp3ListModel->setStringList(musicList);
    9. ui->listView->setModel(mp3ListModel);
    10. ui->listView->selectAll();
    11. }else{
    12. mp3ListInit();
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 

  6. #5
    Join Date
    Apr 2009
    Posts
    35
    Thanks
    9
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Android

    Default Re: a better signal

    Qt Code:
    1. connect(selectionGroupModel,\
    2. SIGNAL(currentRowChanged( const QModelIndex & , const QModelIndex & )),\
    3. this,\
    4. SLOT(selectionChanged( const QModelIndex & , const QModelIndex & )));
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void MusicSettingsWidget::selectionChanged( const QModelIndex & current, const QModelIndex & previous )
    2. {
    3. qDebug()<<"selectionChanged";
    4.  
    5. // qDebug()<<"select change!"<<index.data().toString();
    6. if ( current.data().toString() != "all music" ){
    7. musicSettings4a6ConfigFile->beginGroup("GroupList");
    8. QStringList musicList;
    9. qDebug()<<"current.data().toString()"<<current.data().toString();
    10. QString musicNames;
    11. musicNames = musicSettings4a6ConfigFile->value( current.data().toString() ).toString();
    12. qDebug()<<"musicNames"<<musicNames;
    13. musicList = musicNames.split(";",QString::SkipEmptyParts);
    14. musicList.removeDuplicates();
    15. musicSettings4a6ConfigFile->endGroup();
    16. mp3ListModel->setStringList(musicList);
    17. ui->listView->setModel(mp3ListModel);
    18. ui->listView->selectAll();
    19. }else{
    20. mp3ListInit();
    21. ui->listView->selectAll();
    22. }
    23. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. listview
    By addu in forum Qt Programming
    Replies: 2
    Last Post: 11th May 2009, 12:05
  2. Editing directly in a ListView!
    By Humble in forum Qt Programming
    Replies: 2
    Last Post: 29th August 2007, 08:37
  3. How to return elements from a ListView
    By nikau in forum Newbie
    Replies: 1
    Last Post: 23rd January 2007, 07:44
  4. ListView Dynamic Popup menu
    By raphaelf in forum Newbie
    Replies: 3
    Last Post: 14th October 2006, 19:26
  5. filtering big listview causes slowdown
    By soul_rebel in forum KDE Forum
    Replies: 1
    Last Post: 24th May 2006, 13:31

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.