bauervision bauervision - 2 months ago 32
C++ Question

QTreeWidget select first row

I've seen the solution for python, but I need to know how to do it outside of python.

Here is what I have:

myTree->setCurrentIndex(myTree->currentIndex().sibling(0,0));


I also understand that setCurrentItem is a good way to go, but I can't get that to work either.

Answer

Assuming myTree->topLevelItem(0) does not return nullptr, you can use the following:

myTree->setCurrentItem(
    myTree->topLevelItem(0),    // item
    0,                          // column
    QItemSelectionModel::Select // command
);

See Qt's documentation.