Discussion Board

Results 1 to 5 of 5
  1. #1
    Regular Contributor mkhpad's Avatar
    Join Date
    Nov 2011
    Posts
    104
    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 Expert symbianyucca's Avatar
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    28,664
    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 mkhpad's Avatar
    Join Date
    Nov 2011
    Posts
    104
    Not yet will try

  4. #4
    Nokia Developer Champion rahulvala's Avatar
    Join Date
    Oct 2008
    Location
    INDIA
    Posts
    2,293
    According to your example this is useful :

    QListWidgetItem::setSelected
    regards,
    rahul

  5. #5
    Regular Contributor mkhpad's Avatar
    Join Date
    Nov 2011
    Posts
    104
    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
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved