Adding CheckBoxes In ListView in Qt-4



  • hii,this is my code...I want to display all the .dll files present in a directory as checkable items in a list....how can i do this....can any 1 help me for this...
    i had already done this using Q3CheckListItem....but now i want to use any new method that exist in Qt4...and dont want to use the Qt3 Support...

    @
    QStringList fileTypes;
    QDir dir;
    QFileInfo fileInfo;
    QStringList files;
    Q3CheckListItem *item;

    listView->setResizeMode( Q3ListView::LastColumn );
    listView->addColumn( "Extension" );
    //view.show();
    //ui->listView->header()->hide();

    fileTypes << "_*.dll" ;
    dir.setPath("E:/qtpro/ext");
    dir.setNameFilters(fileTypes);
    files = dir.entryList();

    for (int i = 0; i < files.size(); ++i)
    {
    fileInfo = files.at(i);
    item = new Q3CheckListItem(listView,QString("%1").arg(fileInfo.fileName()),Q3CheckListItem::CheckBox );
    }
    @

    EDIT: please use @-tags for code segments, Gerolf


  • Moderators



  • Feel free to ask any questions on the use of the code referenced above, or make suggestions for improvements. I am the author of that code, so I am interested in your feedback.

    Note that QFileSystemModel is capable of filtering, so filtering based on the extension is trivial.



  • The Qt4 QListView is a one dimensional MVC-Container. Therefore you need a model, which reacts on the role Qt::CheckStateRole in its data method.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.