My listview is not gaining the keyboard focus in Qt
Posted
by Solitaire
on Stack Overflow
See other posts from Stack Overflow
or by Solitaire
Published on 2010-03-25T09:22:33Z
Indexed on
2010/03/25
9:23 UTC
Read the original article
Hit count: 372
Hi,
i am trying to operate the listview itesm through keyboard focus, its not moving.. can you folks suggest where i am wrong.
if i click on the listview from mouse, listview is gaining the focus. i dont no what is wrong.
#include <QtGui>
#include <QApplication>
class Newlist : public QListView
{
public:
Newlist(QWidget *parent = 0);
~Newlist(){};
public:
QListView *list;
QStringListModel *model;
};
Newlist::Newlist(QWidget *parent)
: QListView(parent)
{
list = new QListView(this);
list->setViewMode(QListView::ListMode);
list->setSelectionMode(QAbstractItemView::SingleSelection);
list->setMinimumSize(300,500);
model = new QStringListModel(this);
QStringList strlist;
strlist<<"Test"<<"fest"<<"mest";
list->setModel(model);
model->setStringList(strlist);
QModelIndex index = model->index(1,0);
list->setCurrentIndex(index);
QVBoxLayout *layout = new QVBoxLayout(this);
layout->addWidget(list);
setLayout(layout);
list->setFocus();
}
class Test : public QMainWindow
{
public:
Test(QWidget *parent = 0);
~Test(){};
private:
Mylistview *newlist;
QVBoxLayout *layout;
};
Test::Test(QWidget *parent)
: QMainWindow(parent)
{
layout = new QVBoxLayout();
newlist = new Mylistview();
this->setCentralWidget(newlist);
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Test test;
test.showMaximized();
return a.exec();
}
Thanks in advance
© Stack Overflow or respective owner