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. Getting QTreeWidgetItem's height
Forum Updated to NodeBB v4.3 + New Features

Getting QTreeWidgetItem's height

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 6.6k 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.
  • D Offline
    D Offline
    Davita
    wrote on last edited by
    #1

    Hi. Sorry for this stupid question, I just couldn't find any solution for my problem. I need to get the height of QTreeWidgetItem. QTreeWidgetItem::sizeHint always returns -1. I just can't figure out what I'm doing wrong.

    @ QTreeWidgetItem *row = new QTreeWidgetItem();

            row->setText(1, fi.fileName());
            row->setText(3, history->createDate().toString(trs("DateTimeFormat")));
            ui->trwHistory->addTopLevelItem(row);
        qDebug() << row->sizeHint(1).height(); // Always -1
    

    @

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dbzhang800
      wrote on last edited by
      #2

      Yes, sizeHint should be set using setSizeHint() by yourself, otherwise a default QSize() will be returned.

      Debao

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Davita
        wrote on last edited by
        #3

        Ok, thanks but that doesn't answer my question. How should I get the height of my QTreeWidgetItem?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mkuettler
          wrote on last edited by
          #4

          You might try the protected function
          @
          int rowHeight ( const QModelIndex & index ) const
          @

          of your QTreeWidget (defined in QTreeView). I am not sure why it is protected, because I don't know that interface very well. If you can not access protected functions in that context you could define a new function that exposes this information publicly. But there must be a reason why Qt doesn't do that in the first place, so probably there is a more elegant solution.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mkuettler
            wrote on last edited by
            #5

            I forgot to mention: you can get the QModelIndex by calling the function
            @
            QModelIndex QTreeWidget::indexFromItem ( QTreeWidgetItem * item, int column = 0 ) const
            @

            1 Reply Last reply
            0
            • P Offline
              P Offline
              Phil Weinstein
              wrote on last edited by
              #6

              The height of the result of this QTreeWidget method, called with a given QTreeWidgetItem, does the trick (for QTreeWidget -- this isn't usable for QTreeView, of course):

              QRect QTreeWidget::visualItemRect (const QTreeWidgetItem* item) const;

              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