×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Regular Contributor
    Join Date
    Nov 2011
    Posts
    104

    Post How to highlight an item in QListwidget or Qlistview?

    Hi all,
    I had made a list view which displays a list of items .What i am trying for is i need to highlight the item when an item clicked.I came to know that QListWidget::setSelected is used to highlight the item.

    I dont know how and where to use this in my code can anyone please with this?
    Here is my code:
    #include "mainwindow.h"

    #include <QtGui/QApplication>
    #include<QListWidget>
    #include<QHBoxLayout>


    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);

    QListWidget *listWidget = new QListWidget();
    listWidget->setSortingEnabled(true);


    listWidget->addItem(new QListWidgetItem("Banana"));
    listWidget->addItem(new QListWidgetItem("Apple"));
    listWidget->addItem(new QListWidgetItem("Orange"));
    listWidget->addItem(new QListWidgetItem("Grapes"));
    listWidget->addItem(new QListWidgetItem("Pineapple"));
    listWidget->addItem(new QListWidgetItem("Sugarcane"));
    listWidget->addItem(new QListWidgetItem("Coconut"));
    listWidget->addItem(new QListWidgetItem("Mango"));

    QHBoxLayout *layout = new QHBoxLayout();
    layout->addWidget(listWidget);


    QMainWindow w;
    // w.setStyleSheet("* { background-color:rgb(199,147,88); padding: 7px ; color:rgb(255,255,255)}");
    w.setCentralWidget(listWidget);
    w.showMaximized();




    return app.exec();
    }



    Regards,
    Harish

  2. #2
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,168

    Re: How to highlight an item in QListwidget or Qlistview?

    Generally you could use functions for an item, after adding it to the lists item, thusa have you tried calling the function after adding the items ?

  3. #3
    Regular Contributor
    Join Date
    Nov 2011
    Posts
    104

    Re: How to highlight an item in QListwidget or Qlistview?

    Not yet will try

  4. #4
    Super Contributor
    Join Date
    Oct 2008
    Location
    INDIA
    Posts
    2,326

    Re: How to highlight an item in QListwidget or Qlistview?

    According to your example this is useful :

    QListWidgetItem::setSelected
    regards,
    rahul

  5. #5
    Regular Contributor
    Join Date
    Nov 2011
    Posts
    104

    Re: How to highlight an item in QListwidget or Qlistview?

    Thank you rahul.

Similar Threads

  1. Replies: 1
    Last Post: 2011-05-20, 12:27
  2. Highlight an item in qlistview
    By Guilo19 in forum Qt
    Replies: 3
    Last Post: 2010-07-12, 15:30

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×