Results 1 to 7 of 7

Thread: QListWidget and connect

  1. #1
    Join Date
    Oct 2009
    Posts
    25
    Thanks
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default QListWidget and connect

    Hi,
    Right now i have a QListWidget with a few QListWidgetItem in it,
    and i would like to connect the ItemClicked function to get the string or the row number of the clicked row.

    Thank you for any help

    Shiran

  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: QListWidget and connect

    so, what's the problem? use QListWidget::itemClicked signal and then process pointer to QListWidgetItem which has QListWidgetItem::text. for row determination use QListWidget::row.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QListWidget and connect

    as an addendum to the private mail:

    You also can use QListWidget::selectedItems() to determinate the selected items at any time without using the itemClicked signal.

  4. #4
    Join Date
    Oct 2009
    Posts
    25
    Thanks
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QListWidget and connect

    The problem is that i cant build the connect command

    My QListWidget called List

    Can anyone help me with the connect command,
    I just want to get the string or int of the clicked line by the user

    Thanks,
    shiran


  5. #5
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QListWidget and connect

    The problem is that i cant build the connect command
    What did you try till now ?

  6. #6
    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: QListWidget and connect

    Qt Code:
    1. //h
    2. ...
    3.  
    4. class MyWidget: public QWidget
    5. {
    6. Q_OBJECT
    7. public:
    8. MyWidget(QWidget *parent = 0);
    9.  
    10. private slots:
    11. void itemClicked(QListWidgetItem *item);
    12.  
    13. private:
    14. QListWidget *m_myListWidget;
    15. };
    16. ...
    17. //cpp
    18. MyWidget::MyWidget(QWidget *parent)
    19. : QWidget(parent)
    20. {
    21. m_myListWidget = new QListWidget(this);
    22. ...
    23. connect(myListWidget, SIGNAL(itemClicked(QListWidgetItem *)), SLOT(itemClicked (QListWidgetItem *)));
    24. ...
    25. }
    26. ...
    27. void MyWidget::itemClicked(QListWidgetItem *item)
    28. {
    29. if (!item)
    30. return;
    31. qDebug() << "row [" << m_myListWidget->row(item) << "] == " << item->text();
    32. }
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  7. #7
    Join Date
    Oct 2009
    Posts
    25
    Thanks
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QListWidget and connect

    Ok GREAT
    Thanks i will try it

Similar Threads

  1. Segmentation Fault accessing QListWidget
    By ljshap in forum Newbie
    Replies: 2
    Last Post: 20th December 2008, 14:00
  2. How to make QListWidget items editable?
    By montylee in forum Qt Programming
    Replies: 14
    Last Post: 3rd October 2008, 10:57
  3. cannot write to QListWidget or QLineEdit
    By landonmkelsey in forum Qt Programming
    Replies: 12
    Last Post: 18th August 2008, 08:37
  4. Replies: 18
    Last Post: 23rd July 2007, 06:58
  5. extract item from QListWidget
    By impeteperry in forum Qt Programming
    Replies: 2
    Last Post: 13th May 2006, 20:41

Tags for this Thread

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.