[Qt-interest] what is the mistake in my code

Ramesh ramesh.bs at robosoftin.com
Thu Mar 25 13:59:35 CET 2010


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.

Here is my code,

 

class Newlist : public QWidget
   {
public:
 Newlist(QWidget *parent = 0);
    ~Newlist(){};

public:
    QListView *list;
    QStringListModel *model;


 };

Newlist::Newlist(QWidget *parent)
    : QWidget(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;
    QStackedWidget *stack;
};

Test::Test(QWidget *parent)
    : QMainWindow(parent)
{

 layout = new QVBoxLayout();
 newlist = new Mylistview(); 
 stack = new QStackedWidget(this);

 stack->addWidget(newlist);

 this->setCentralWidget(stack);

}


int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Test test;
    test.showMaximized(); 

    return a.exec();
}

 


-----------------------------------------------
Robosoft Technologies - Come home to Technology

Disclaimer: This email may contain confidential material. If you were not an intended recipient, please notify the sender and delete all copies. Emails to and from our network may be logged and monitored. This email and its attachments are scanned for virus by our scanners and are believed to be safe. However, no warranty is given that this email is free of malicious content or virus.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100325/1590343e/attachment.html 


More information about the Qt-interest-old mailing list