Results 1 to 9 of 9

Thread: How to write coding for the selected item in the QListWidget?

  1. #1
    Join Date
    Nov 2011
    Posts
    45
    Qt products
    Qt4
    Platforms
    Symbian S60

    Post How to write coding for the selected item in the QListWidget?

    Hi all,
    I am having a QListwidget which contains some items in it.

    Now what i am trying for is:When i click anyone of those items in the list it should display some information about it.
    Here is the code of mine:

    Qt Code:
    1. void MainWindow:n_pushButton_clicked()
    2. {
    3.  
    4. QListWidget *listWidget = new QListWidget();
    5.  
    6. listWidget->addItem(new QListWidgetItem("A"));
    7. listWidget->addItem(new QListWidgetItem("B"));
    8. listWidget->addItem(new QListWidgetItem("C"));
    9. listWidget->addItem(new QListWidgetItem("D"));
    10. listWidget->addItem(new QListWidgetItem("E"));
    11. listWidget->addItem(new QListWidgetItem("F"));
    12. listWidget->addItem(new QListWidgetItem("G"));
    13. listWidget->setStyleSheet("* { background-color:black; padding: 7px ; color: white}");
    14.  
    15. listWidget->setStyleSheet( " QListWidget::item:selected:active {background: qlineargradient(x1: 0, y1: 0, stop: 0 red);}");
    16.  
    17. listWidget->showFullScreen();
    18.  
    19. }
    To copy to clipboard, switch view to plain text mode 



    If i click A-it should display something about "A" and for each and every item.


    Is there any code of property so that i can finish my work.


    Anyone help me with this.

    Thanks and Regards,
    Harish.M
    Last edited by Lykurg; 24th December 2011 at 08:19. Reason: missing [code] tags

  2. #2
    Join Date
    Jul 2010
    Posts
    53
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to write coding for the selected item in the QListWidget?

    display how? popup? heard about
    Qt Code:
    1. void itemClicked ( QListWidgetItem * item );
    To copy to clipboard, switch view to plain text mode 

    signal?

  3. #3
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to write coding for the selected item in the QListWidget?

    Now what i am trying for is:When i click anyone of those items in the list it should display some information about it.
    What is 'it'?? The list widget? The list widget should display more information?
    Last edited by Lykurg; 24th December 2011 at 08:20. Reason: changed [i] to [quote]
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  4. #4
    Join Date
    Nov 2011
    Posts
    45
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: How to write coding for the selected item in the QListWidget?

    I need to display a QMessageBox?

    It should display some text in a QMessageBox when any item in the list is selected....

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to write coding for the selected item in the QListWidget?

    Connect the itemClicked() or currentItemChanged() signal of the list widget to a slot that display the message box. Both slots provide a way to access the data of the clicked item.

  6. #6
    Join Date
    Nov 2011
    Posts
    45
    Qt products
    Qt4
    Platforms
    Symbian S60

    Post Re: How to write coding for the selected item in the QListWidget?

    Thank you Chris it got worked..

    Thank you once again.

    Now i am trying to display different messages in a QMessageBox when selecting each item.

    Suppose if select "A" it should display A for APPLE and if "B" is selected it displays B for BANANA...

    How to add this property in this?
    Last edited by harish; 25th December 2011 at 07:05.

  7. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to write coding for the selected item in the QListWidget?

    The clicked item is passed in to the slot. You can look at which item it is and make decision about what to display.

  8. #8
    Join Date
    Nov 2011
    Posts
    45
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: How to write coding for the selected item in the QListWidget?

    Ok thank you chris..

    Thank you for your guidance and help.

  9. #9
    Join Date
    Apr 2013
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to write coding for the selected item in the QListWidget?

    Hi, Am a newbie to qt and require some guidance from you guys.
    How to place the selected item to center in a qlistwidget ?.
    Assume that there are 10 items in a qlistwidget and only 5 index values are visible at a time. If I select the fourth index value or item, how could i scroll the selected item to the 2nd index and view the next items from the fourth index.

    Is there any way to do this?

    Thanks ...

Similar Threads

  1. popupmenu for QTreeWidget's item when a particular item selected.
    By vinod sharma in forum Best Practices in Qt Programming
    Replies: 1
    Last Post: 22nd January 2010, 10:45
  2. Replies: 1
    Last Post: 20th January 2010, 08:38
  3. Replies: 2
    Last Post: 11th January 2010, 23:15
  4. QListWidgetItem remove an item
    By mattia in forum Newbie
    Replies: 4
    Last Post: 9th November 2007, 07:57
  5. Remove selected QListWidgetItem
    By xgoan in forum Newbie
    Replies: 7
    Last Post: 28th September 2006, 14:42

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.