How to autofit widget size and position to a cell in QTreeWidget?



  • I pragrammaticaly create a QTreeWidget (myTree).
    Then I pragrammaticaly add some items (item1, item2).
    Then I add two QLabel widgets to two items (QTreeWidgetItem) by

    myTree->setItemWidget(item1, 0, myLabel1);
    myTree->setItemWidget(item2, 0, myLabel2);
    

    And then I try to resize the row of the item pragrammaticaly. If I use an

    item1->setSizeHint(0, QSize(myWidth, myHeight) );
    

    the row chaged. But the myLabel1 is not. If I use an

    item1->setSizeHint(0, QSize(myWidth, myHeight) );
    myLabel1->resize(myWidth, myHeight);
    

    everething is ok but the row of myLabel2 mis adjusting to label by position.
    Can I do something to auto-adjusting a widget (by size and position) to a cell of QTreeWidget?

    P.S. After any resizing of tree (resize by width or expand/collapse node) widgets updates correctly.



  • myTree->resizeColumnToContent(0);


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.