Results 1 to 5 of 5

Thread: how to get item's text or path from QListVIew

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2008
    Posts
    43
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default how to get item's text or path from QListVIew

    Hello,

    I have a problem, I have a ListView that displays a list of items of a directory.
    is there a way to copy selected item's text or path into a var using QListViewItem.

    e.x
    QListView:

    item1
    item2
    item3

    user selects item2 and then clicks a button, then item's text "item2" or item's path (e.x "/usr/bin/item2") is saved into a QString var.

    is there a way to do that?
    thank you, and sorry for my poor english.

  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 get item's text or path from QListVIew

    you can catch this signal http://doc.trolltech.com/3.3/qlistview.html#clicked in your widget and then use this method for getting the text http://doc.trolltech.com/3.3/qlistviewitem.html#text

    or I didn't understand something?

  3. #3
    Join Date
    Sep 2008
    Posts
    43
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to get item's text or path from QListVIew

    hey spirit, thx for the anwser..

    ill try to do it with these methods.

  4. #4
    Join Date
    Sep 2008
    Posts
    43
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to get item's text or path from QListVIew

    ok here's the code
    Qt Code:
    1. //copy selected package name to pkgName var
    2. if(listViewItem->isSelected())
    3. {
    4. listViewItem->setSelected( TRUE );
    5. pkgName = ( listViewItem->text ( 0 ) );
    6. }
    To copy to clipboard, switch view to plain text mode 

    then i click an item in the list and run a KMessageBox, but pkgName var is empty..
    what am i doing wrong?

  5. #5
    Join Date
    Sep 2008
    Posts
    43
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to get item's text or path from QListVIew

    ok problem solved, the solution was very easy after all

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 10:49
  2. QListView with icons on top of the text, not at the left
    By vfernandez in forum Qt Programming
    Replies: 7
    Last Post: 19th February 2009, 05:19
  3. Navigate through qlistview items with shortcuts
    By jiveaxe in forum Qt Programming
    Replies: 4
    Last Post: 10th January 2008, 12:28
  4. Items in QListView should sort on Header Click
    By vinnu in forum Qt Programming
    Replies: 14
    Last Post: 10th November 2006, 13:49
  5. moving Qlistview items
    By :db:sStrong in forum Qt Programming
    Replies: 0
    Last Post: 21st February 2006, 13: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.