PDA

View Full Version : How to write coding for the selected item in the QListWidget?



harish
23rd December 2011, 13:10
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:


void MainWindow:n_pushButton_clicked()
{

QListWidget *listWidget = new QListWidget();

listWidget->addItem(new QListWidgetItem("A"));
listWidget->addItem(new QListWidgetItem("B"));
listWidget->addItem(new QListWidgetItem("C"));
listWidget->addItem(new QListWidgetItem("D"));
listWidget->addItem(new QListWidgetItem("E"));
listWidget->addItem(new QListWidgetItem("F"));
listWidget->addItem(new QListWidgetItem("G"));
listWidget->setStyleSheet("* { background-color:black; padding: 7px ; color: white}");

listWidget->setStyleSheet( " QListWidget::item:selected:active {background: qlineargradient(x1: 0, y1: 0, stop: 0 red);}");

listWidget->showFullScreen();

}



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

GreenScape
23rd December 2011, 18:08
display how? popup? heard about


void itemClicked ( QListWidgetItem * item );


signal?

amleto
23rd December 2011, 18:24
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?

harish
25th December 2011, 04:18
I need to display a QMessageBox?

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

ChrisW67
25th December 2011, 05:30
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.

harish
25th December 2011, 06:03
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?

ChrisW67
25th December 2011, 10:46
The clicked item is passed in to the slot. You can look at which item it is and make decision about what to display.

harish
26th December 2011, 07:17
Ok thank you chris..

Thank you for your guidance and help.

Rajaguru.M
28th May 2013, 13:03
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 ... :)