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 Update on Monday, May 27th 2025

[Solved]Listview columnheaders

Scheduled Pinned Locked Moved General and Desktop
11 Posts 3 Posters 4.6k 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.
  • T Offline
    T Offline
    toho71
    wrote on 11 Oct 2011, 06:01 last edited by
    #1

    Hi
    I'm trying to use Qlistview to show a list of objects.
    In other programlanguages there is no problems to add/set Columnheaders and add items and subitems.

    But not in qt4 there is no addColumn and no addItem.

    Maybe I should use another component because i want to sort the columns when I click on the columnheader

    1 Reply Last reply
    0
    • F Offline
      F Offline
      fluca1978
      wrote on 11 Oct 2011, 06:26 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 11 Oct 2011, 06:31 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 11 Oct 2011, 06:34 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 11 Oct 2011, 06:38 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 11 Oct 2011, 07:04 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 11 Oct 2011, 07:44 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 11 Oct 2011, 08:17 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 11 Oct 2011, 08:41 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 11 Oct 2011, 08:47 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 11 Oct 2011, 09:23 last edited by
                        #11

                        I found what i was lokking for when i tested Treeview

                        1 Reply Last reply
                        0

                        1/11

                        11 Oct 2011, 06:01

                        • Login

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