PDA

View Full Version : QListWidget and connect



shiranraviv
5th October 2009, 12:08
Hi,
Right now i have a QListWidget with a few QListWidgetItem in it,
and i would like to connect the ItemClicked function to get the string or the row number of the clicked row.

Thank you for any help

Shiran

spirit
5th October 2009, 12:28
so, what's the problem? use QListWidget::itemClicked signal and then process pointer to QListWidgetItem which has QListWidgetItem::text. for row determination use QListWidget::row.

Lykurg
5th October 2009, 16:27
as an addendum to the private mail:

You also can use QListWidget::selectedItems() to determinate the selected items at any time without using the itemClicked signal.

shiranraviv
6th October 2009, 12:05
The problem is that i cant build the connect command

My QListWidget called List

Can anyone help me with the connect command,
I just want to get the string or int of the clicked line by the user

Thanks,
shiran

:confused:

aamer4yu
6th October 2009, 12:11
The problem is that i cant build the connect command
What did you try till now ?

spirit
6th October 2009, 12:12
//h
...
class QListWidget;
class QListWidgetItem;

class MyWidget: public QWidget
{
Q_OBJECT
public:
MyWidget(QWidget *parent = 0);

private slots:
void itemClicked(QListWidgetItem *item);

private:
QListWidget *m_myListWidget;
};
...
//cpp
MyWidget::MyWidget(QWidget *parent)
: QWidget(parent)
{
m_myListWidget = new QListWidget(this);
...
connect(myListWidget, SIGNAL(itemClicked(QListWidgetItem *)), SLOT(itemClicked (QListWidgetItem *)));
...
}
...
void MyWidget::itemClicked(QListWidgetItem *item)
{
if (!item)
return;
qDebug() << "row [" << m_myListWidget->row(item) << "] == " << item->text();
}

shiranraviv
6th October 2009, 12:56
Ok GREAT
Thanks i will try it