Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

    How to add manually a column to a treewidget?

    General and Desktop
    4
    8
    11226
    Loading More Posts
    • 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
      Leon last edited by

      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 Reply Quote 0
      • L
        lgeyer last edited by

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

        1 Reply Last reply Reply Quote 0
        • G
          giesbert last edited by

          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 Reply Quote 0
          • L
            Leon last edited by

            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 Reply Quote 0
            • L
              lgeyer last edited by

              "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 Reply Quote 1
              • L
                Leon last edited by

                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 Reply Quote 0
                • A
                  andre last edited by

                  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 Reply Quote 0
                  • G
                    giesbert last edited by

                    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 Reply Quote 0
                    • First post
                      Last post