Important: Please read the Qt Code of Conduct -

Relative positions of widgets

  • Hello,

    I encounter the following problem:
    I have a QTreeWidget which inherits QAbstractScrollArea. When the tree is long enough, the vertical scroll bars appears.

    I wouls like to know the position od the tree window ( in pixel or whatever ) inside that QAbstractScrollArea.
    For example, when the tree is small enough for the scroll to be dissabled, this position is 0;
    And when for example there ten items above the first item visible, I'd like the length of all those items which corresponds to the distance from the begining of the tree.

    Is there a way to do it?


  • The tree view is not inside the QAbstractScrollArea, it is an QAbstractScrollArea.

    QAbstractItemView provides a method visualRect() to retreive the rect of an item, and you can map positions to using the viewPorts()'s mapTo... methods.

  • Thanks for the answer.
    Okay, but I don't see how that could help me. I want to know the position of the tree compared to the area. If we can only the the second half o the tree for example, how could i know?

  • The information above really gives you all the tools you need.

    I am wondering: what do you need this information for?

  • When a browse all items of my tree and apply a treatement on them, the scrolling goes down automaticaly. I would like to know the position of the tree before the treatement to set it back after the treatement. I managed to do it by getting the value of the scrollbar and set it after the treatement, it works but too slowly. I figured if I could directly get the position of the tree inside the area it could be more perfomrmant.

    It might not be clear. Sorry for that.

  • After some more works, the problem could be change.

    In fact, during the treatement I apply on each items, I use the method :
    @void QTreeWidget::setCurrentItem ( QTreeWidgetItem * item, int column, QItemSelectionModel::SelectionFlags command ) @

    to change their selection.

    It turns out that the fact of using such a method on items that are too deep into the tree for being directly visible automaticaly makes the view of the tree change in order to make them visible.
    Of course I don't want the view of the tree to change when those action are performed.

    Anyone has a idea to forbid that update of the display of the tree?


Log in to reply