Qt World Summit: Submit your Presentation

What layout to use for data listing if I don't need most of the model features?

  • I have a set that stores a list of numbers and I want to output them in a Qdialog. I also want to apply an conversion to each number and output them as well. The layout I'm thinking is vertical table like layout that holds the number and the conversion result in two columns like this

    Number            Conversion Result
     300                6500 from 300
     350                7000 from 350
     400                7500 from 400

    I have tried out the table/view stuffs like QStandardItemModel and QStringListModel, but I don't need their features. For example, I don't need the data to be modifiable when double clicked, and I don't need sorting when the header was clicked. All I need are to highlight row when the row was clicked and the table be scrollable for longer list.

    Do I still need model for this? And what layout should I be using?

  • Lifetime Qt Champion

    I think using a QTableWidget would be the fastest way.
    You dont need a model for that. just insert items.

  • @mrjj

    Thanks I got it to work.

    QStringList tableHeader = {"Number", "Result"};
    int rowCounter = 0;
    for(int i : numberSet)
        ui->tableWidget->setItem(rowCounter, 0, new QTableWidgetItem(QString::number(i)));
        ui->tableWidget->setItem(rowCounter, 1, new QTableWidgetItem(someConversion(i)));

Log in to reply