0

So I'm using QTCreator to create a GUI for a project. I'm reading items from a file, and then those items are imported into a ListWidget with checkboxes next to each item. I was wondering if it's possible to have the checkbox along with a spin box or some other sort of numeric attribute tied to each item, and if so could you explain how? Edit: If anyone know hows to add any of the editable text boxes instead that'd actually work even better. This is what I'm currently doing to open/read the file:

QFile ingFile("/root/Desktop/file.txt");
ingFile.open(QIODevice::ReadOnly);
QTextStream in(&ingFile);
QStringList inglist;
QString line = in.readLine();
while(!line.isNull()){
    inglist.append(line);
    line = in.readLine();
}
QStringListIterator it(inglist);
while(it.hasNext()){
    QListWidgetItem *listitem = new QListWidgetItem(it.next());
    listitem->setCheckState(Qt::Unchecked);
    ui->ingList->addItem(listitem);
}

Thanks!

Bob343
  • 1
  • 2
  • You should use `QTableView` with `QStandardItemModel` and a subclass of `QStyledItemDelegate`. – Pavel Strakhov Jun 12 '15 at 22:23
  • @PavelStrakhov How would I go about doing this? I'm really not that familiar with QT, definitely still learning. – Bob343 Jun 12 '15 at 22:44
  • Check out [Model/View Tutorial](http://doc.qt.io/qt-5/modelview.html) and [Spin Box Delegate Example](http://doc.qt.io/qt-5/qtwidgets-itemviews-spinboxdelegate-example.html). – Pavel Strakhov Jun 13 '15 at 00:39

0 Answers0