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?

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 845 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 11 Aug 2018, 20:42 last edited by lansing 8 Nov 2018, 20:43
    #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
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 11 Aug 2018, 20:54 last edited by mrjj 8 Nov 2018, 20:56
      #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 12 Aug 2018, 01:40
      2
      • M mrjj
        11 Aug 2018, 20:54

        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 12 Aug 2018, 01:40 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

        1/3

        11 Aug 2018, 20:42

        • Login

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