[Qt-interest] List widget item - gaining focus
linux newbie
linux.newbie79 at gmail.com
Tue Mar 16 10:49:51 CET 2010
*
HI,
I am having issue in focusing list widget item.
I created a simple test project. The display routine creates a new layout
and adds the listwidget into it. When this routine is called first time, the
list widget item is highlighted as expected. Event filter is attached to
this dialog and on pressing "Return" key, dataChanged() signal is emitted
which in turn calls my display() routine.
Inside display() routine, previous layout is deleted along with its
widget(list widget). But now, the item in listwidget is not highlighted i.e
list widget is not gained focus, but when I click the key, it gets focus.
Can anyone let me know the mistake I made in the below code.
Dialog::Dialog(QWidget *parent):QDialog(parent)*
{
this->installEventFilter(this);
connect(this, SIGNAL(dataChanged()), this,
SLOT(display()));
this->display();
}
*void Dialog::display()*
{
QLayout *currLayout = this->layout();
if (currLayout != NULL)
{
QLayoutItem *child;
while ((child = currLayout->takeAt(0)) != 0)
{
QWidget *childWidget = child->widget();
childWidget->deleteLater();
}
delete currLayout;
}
QListWidget *listWidget = new QListWidget();
listWidget->addItem(QString("1"));
listWidget->addItem(QString("2"));
listWidget->addItem(QString("3"));
listWidget->setCurrentRow(1);
QVBoxLayout *layout = new QVBoxLayout();
layout->addWidget(listWidget);
this->setLayout(layout);
this->show();
}
*bool Dialog::eventFilter(QObject *obj, QEvent *event)*
{
if (event->type() == QEvent::KeyPress)
{
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
int key = keyEvent->key();
if (key == Qt::Key_Return)
{
emit dataChanged();
}
}
return false;
}
Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100316/832c1d24/attachment.html
More information about the Qt-interest-old
mailing list