[Qt-interest] Event handling in QListWidget
Malyushytsky, Alex
alex at wai.com
Fri Feb 6 01:33:47 CET 2009
I see a few problems here. It looks like you are trying to do two things:
a) populate QListWidget
b) connect QListWidget instance with some slots
So your code should be re-writen like:
listWidget = new QListWidget(this);
// a) insert your items. There are a few different ways to do it:
// 1 way
// In this case You need to insert QListWidgetItem into QListWidget (this code is absent in your example).
// To do this you MUST create it with new, otherwise this item will be deleted as soon Item is out of scope:
QListWidgetItem *Item = new QListWidgetItem(this);
Item ->setText(tr("Item1"));
listWidget->insertItem( 0, Item); // insert
// 2 way
// If you don't need to set some specific to QListWidgetItem* properties you might not need QlistWidgetItem pointer,
// so you can just use QListWidget::addItem
QString label ( tr( "Item2" ) );
listWidget->addItem (label );
// for more ways, see documentation
// b) connecting signals to your slots
// You should review Signals and Slots information in QT documenntation, cause it looks like you misunderstand it
// I would use signal itemPressed, depending on your needs you might use itemClicked
// the difference is Pressed means item was clicked and mouse button was released over the items.
connect(listWidget, // object (instance) - signal sender
SIGNAL( itemPressed ( QListWidgetItem* ) ), // signal declaration - No Item (object) there
this, // object (instance) slot owner ( signal reciever )
SLOT( ItemDisplay1( QListWidgetItem* ) ); // slot declaration - No Item (object) there
// connect(listWidget, SIGNAL( itemPressed ( QListWidgetItem* ) ), this, SLOT( ItemDisplay1( QListWidgetItem* ) );
//
a) and b) sections are independent, you don't need pointers to QListWidgetItem to connect QListWidget signal to your slot,
so you can remove section a) from here and popluate populate listWidget later.
Hope this help,
Alex Malyushytsky
________________________________________
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Ravi_Kalepalli
Sent: Thursday, February 05, 2009 2:39 AM
To: qt-interest at trolltech.com
Subject: [Qt-interest] Event handling in QListWidget
Hi All,
I am constructing listwidget for handling events using signal and slot.
When I am using
listWidget = new QListWidget(this);
QListWidgetItem Item(listWidget);
connect(listWidget,SIGNAL(itemPressed(Item)),this, SLOT(ItemDisplay1(Item )));
* void itemClicked ( QListWidgetItem * item )
* void itemDoubleClicked ( QListWidgetItem * item )
* void itemPressed ( QListWidgetItem * item )
What I want is if I click any item in the widget slot is not getting executed
void Mediagallery::ItemDisplay1(QListWidgetItem * item )
{
QMessageBox msgBox;
msgBox.setText("The document has been modified.");
msgBox.exec();
}
Please suggest me.
Thanks and Regards
Ravi Kalepalli
Telephone: 080-67807807
Mobile: 98807 24688
________________________________________
DISCLAIMER:
This email (including any attachments) is intended for the sole use of the intended recipient/s and may contain material that is CONFIDENTIAL AND PRIVATE COMPANY INFORMATION. Any review or reliance by others or copying or distribution or forwarding of any or all of the contents in this message is STRICTLY PROHIBITED. If you are not the intended recipient, please contact the sender by email and delete all copies; your cooperation in this regard is appreciated.
---------------------------------------------------------------------------------------------------
Weidlinger Associates, Inc. made the following annotations.
"This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you."
"Please consider our environment before printing this email."
More information about the Qt-interest-old
mailing list