coding_neo
25th July 2011, 10:25
Hello:
I have a problem using QListWidget. WHat functionality I would like to have is that I create a QLIstWidget. and I want to be able to doubleclick on an item of the QListWidget and have another UI popup. ( for now I am considering QMessageBox as the other UI).
My code is posted below. When I run it, the QListWidget shows up fine, but when I double click on an item nothing happens ( no message box comes up).
What am I doing wrong? (this code is complete as a standalone, so you can copy and paste it as it is in a file in your ide and run it to get understanding.).
# include <QApplication>
# include <QListWidget>
# include <QListWidgetItem>
# include <QHBoxLayout>
# include <QDialog>
# include <QMessageBox>
class TestList : public QDialog
{
public:
TestList()
{
QListWidget *mList = new QListWidget();
mList->addItem("Walmart");
mList->addItem("Ford Motors");
mList->addItem("Circuit City");
QHBoxLayout *h = new QHBoxLayout();
h->addWidget(mList);
this->setLayout(h);
QListWidgetItem *mItem = new QListWidgetItem();
QObject::connect(mList,SIGNAL(itemDoubleClicked(QL istWidgetItem *mItem)),this,SLOT(test(QListWidgetItem *m)));
}
public slots:
void test(QListWidgetItem *m)
{
QMessageBox *t = new QMessageBox(this);
t->setText(m->text());
t->setVisible(true); // I tried t->show() here as well but to no effect.
}
};
int main(int argc, char*argv[])
{
QApplication app (argc,argv);
TestList *t = new TestList();
t->show();
return app.exec();
}
I have a problem using QListWidget. WHat functionality I would like to have is that I create a QLIstWidget. and I want to be able to doubleclick on an item of the QListWidget and have another UI popup. ( for now I am considering QMessageBox as the other UI).
My code is posted below. When I run it, the QListWidget shows up fine, but when I double click on an item nothing happens ( no message box comes up).
What am I doing wrong? (this code is complete as a standalone, so you can copy and paste it as it is in a file in your ide and run it to get understanding.).
# include <QApplication>
# include <QListWidget>
# include <QListWidgetItem>
# include <QHBoxLayout>
# include <QDialog>
# include <QMessageBox>
class TestList : public QDialog
{
public:
TestList()
{
QListWidget *mList = new QListWidget();
mList->addItem("Walmart");
mList->addItem("Ford Motors");
mList->addItem("Circuit City");
QHBoxLayout *h = new QHBoxLayout();
h->addWidget(mList);
this->setLayout(h);
QListWidgetItem *mItem = new QListWidgetItem();
QObject::connect(mList,SIGNAL(itemDoubleClicked(QL istWidgetItem *mItem)),this,SLOT(test(QListWidgetItem *m)));
}
public slots:
void test(QListWidgetItem *m)
{
QMessageBox *t = new QMessageBox(this);
t->setText(m->text());
t->setVisible(true); // I tried t->show() here as well but to no effect.
}
};
int main(int argc, char*argv[])
{
QApplication app (argc,argv);
TestList *t = new TestList();
t->show();
return app.exec();
}