Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. What layout to use for data listing if I don't need most of the model features?
Forum Update on Monday, May 27th 2025

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
model-viewtable model
3 Posts 2 Posters 848 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lansing
    wrote on last edited by lansing
    #1

    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?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi
      I think using a QTableWidget would be the fastest way.
      You dont need a model for that. just insert items.
      https://wiki.qt.io/How_to_Use_QTableWidget

      L 1 Reply Last reply
      2
      • mrjjM mrjj

        Hi
        I think using a QTableWidget would be the fastest way.
        You dont need a model for that. just insert items.
        https://wiki.qt.io/How_to_Use_QTableWidget

        L Offline
        L Offline
        lansing
        wrote on last edited by
        #3

        @mrjj

        Thanks I got it to work.

        ui->setupUi(this);    
        ui->tableWidget->setColumnCount(2);    
        ui->tableWidget->setRowCount(numberSet.size());
        
        ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
        
        QStringList tableHeader = {"Number", "Result"};
        ui->tableWidget->setHorizontalHeaderLabels(tableHeader);
        
        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)));
            rowCounter++;
        }
        
        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved