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. [Solved]Listview columnheaders
Forum Updated to NodeBB v4.3 + New Features

[Solved]Listview columnheaders

Scheduled Pinned Locked Moved General and Desktop
11 Posts 3 Posters 4.7k Views 1 Watching
  • 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.
  • F Offline
    F Offline
    fluca1978
    wrote on last edited by
    #2

    The model has a method to add columns.
    Maybe a tree view could be also more appropriate for your aim.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      toho71
      wrote on last edited by
      #3

      if I use a treeview could I set it in report mode (list) or could i use a tableview or something instead.

      I think that the listview should be the best component for me in this case.

      When i'm reading the tutorial of the listview there is a addColumn method but not when I'm trying to use it.

      1 Reply Last reply
      0
      • F Offline
        F Offline
        fluca1978
        wrote on last edited by
        #4

        Probably your example is outdated, I remember there was a method like the one you describe in old qt versions. Anyway, if you believe qlistview is the best for your aim, use it and deal with its model. The model has the management of columns.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #5

          A QListView can only display a simple list, either in the form of a normal list, or in the form of a grid of icons. It can not display multiple columns. If you need multiple columns, you should use a QTableView instead. Note that both of them work with QAbstractItemModel derived model to supply the data for the view.

          Edit:
          Oh, and a QListView does not have headers, no matter if your model supplies them or not.

          1 Reply Last reply
          0
          • T Offline
            T Offline
            toho71
            wrote on last edited by
            #6

            Ok
            Thank you all
            Anyone that have a simple exampel of the QTableview
            three columns with headers

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #7

              Just typing something up:
              @
              QStandardItemModel* model = new QStandardItemModel(this);
              model->setColumnCount(3);
              QStringList headerLabels;
              headerLabels<<"Foo" << "Bar" << "Baz";
              model->setHorizontalHeaderLabels(headerLabels);
              model->setRowCount(10);
              for (int row(0); row < 10; ++row) {
              for (int col(0); col < 3; ++col) {
              QString text = QString("row %1 col %2).arg(row).arg(col);
              QStandardItem* itm = new QStandardItem(text);
              model->setItem(row, col, itm);
              }
              }

              m_ui->tableView->setModel(model);
              @

              (typed in editor in forum, not tested as code)

              1 Reply Last reply
              0
              • T Offline
                T Offline
                toho71
                wrote on last edited by
                #8

                It didn't work.
                m_ui->tableView->setModel(model);
                Error
                error: ‘virtual void QTableWidget::setModel(QAbstractItemModel*)’ is private

                but when i tested it on a listview it worked but no columnheaders.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andre
                  wrote on last edited by
                  #9

                  You were talking about a using a QTable_View_, not a QTable_Widget_. Big difference there.

                  1 Reply Last reply
                  0
                  • T Offline
                    T Offline
                    toho71
                    wrote on last edited by
                    #10

                    Yes my misstake sorry

                    Is there a Swipe gesture in this component/widget

                    1 Reply Last reply
                    0
                    • T Offline
                      T Offline
                      toho71
                      wrote on last edited by
                      #11

                      I found what i was lokking for when i tested Treeview

                      1 Reply Last reply
                      0

                      • Login

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