PDA

View Full Version : Adding CheckBoxes In ListView in Qt-4



Ketan Shah
25th May 2011, 09:00
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::CheckBo x );
}

stampede
25th May 2011, 09:05
Again, please use the [CODE] tags.
You may want to read documentation for QListWidgetItem (http://doc.qt.nokia.com/latest/qlistwidgetitem.html) and QListWidget (http://doc.qt.nokia.com/latest/qlistwidget.html).

Santosh Reddy
25th May 2011, 09:07
Have a look at this post, you may need to change QPushButton to QCheckBox

http://www.qtcentre.org/threads/41465-QListView-and-custom-Widgets?p=190790&highlight=#post190790

cooperman
25th September 2014, 12:43
Hi Ketan,
I am wanting to add a check box in column 0 in a ListView and I need to use Qt3.
Is the code snippet above for Qt3?
I am a complete newbie with Qt (any version) and would be so grateful for any information you can give me.
Many thanks,
Gary

anda_skoa
25th September 2014, 15:06
It is almost for Qt3.
In Qt3 the class was calles QCheckListItem (without the "3", this was added to mark it as a compatibility class in Qt4)

Cheers,
_