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. How to add manually a column to a treewidget?

How to add manually a column to a treewidget?

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 12.7k 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
    Leon
    wrote on last edited by
    #1

    I think it is called column.. This is a treewidget:

    !http://i53.tinypic.com/2lwlrt0.jpg(Screen)!

    And the text "History Entries" is the column or what is called..
    I added it with the qt designer ( right click->edit items ).. But how can i add it through code.
    Something like: @ui->treewidget->addcolumn(tr("History Entries");@

    Don't know...

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

      You basically cannot add columns to a view, but you can to the underlying model.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        giesbert
        wrote on last edited by
        #3

        In a TreeWidget, you have to add QTreeWidgetItems.

        You can use "QTreeWidget::setHeaderItem":http://doc.qt.nokia.com/4.7/qtreewidget.html#setHeaderItem or some similar functions.

        Nokia Certified Qt Specialist.
        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

        1 Reply Last reply
        0
        • L Offline
          L Offline
          Leon
          wrote on last edited by
          #4

          You mean items like this?
          !http://i53.tinypic.com/2a85ni1.jpg(sc)!

          Yes i know.. But there must be a way that you can add a column like ( History entries ) trough code...

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lgeyer
            wrote on last edited by
            #5

            "QTreeWidget::setColumnCount()":http://doc.qt.nokia.com/4.7/qtreewidget.html#columnCount-prop
            "QTreeWidgetItem::setData()":http://doc.qt.nokia.com/4.7/qtreewidgetitem.html#setData

            1 Reply Last reply
            1
            • L Offline
              L Offline
              Leon
              wrote on last edited by
              #6

              I don't understand :/

              @QTreeWidgetItem *itemo = new QTreeWidgetItem;
              itemo->setText(QString("History Entries"));
              ui->treeWidget->setHeaderItem(itemo);@

              ?

              First i have this error
              error: no matching function for call to ‘QTreeWidgetItem::setText(QString)’

              Anyway i don't think that setheaderitem will add it as a column..

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

                QTreeWidget works in such a way, that every row is a single item. In that respect, it is different from and inconsistent with QTableWidget that works with an item per cell (so a row is a series of items). That also goes for the header item. If you consult the documentation, you'll notice that QTreeWidgetItem does not have a method setText(QString), but only a setText(int, QString). That explains the error you get.

                The number of columns in your QTreeWidget, can be controlled using the setColumnCount() method, as was pointed out to you before by Lukas. After increasing the column count, you can simply either use the existing header item and set the text for the column, or create new header item if there currently isn't one.

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  giesbert
                  wrote on last edited by
                  #8

                  Hi Leon

                  did you look at tzhe fiunctions I pointed you to?

                  • QTreeWidget::setHeaderItem
                  • QTreeWidget::setHeaderLabel
                  • QTreeWidget::setHeaderLabels

                  [quote author="Gerolf" date="1311327187"]You can use "QTreeWidget::setHeaderItem":http://doc.qt.nokia.com/4.7/qtreewidget.html#setHeaderItem or some similar functions.[/quote]

                  Nokia Certified Qt Specialist.
                  Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                  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