Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QTreeWidget setCurrentIndex



  • Hi, I have a QTreeWidget containing several Tree. First of all i initialize the QTreeWidget to select the first row in the tree.

    ui->tree->topLevelItem(0)->setSelected(true);
    std::cout << " row: " << ui->tree->currentIndex().row() << std::endl;
    

    when i do a cout the current row it always return -1. isnt it it shld be returning 0? Please advise. Thank you.


  • Moderators

    In Qt views, selected index is not the same as current index. So, get the selection, and check the row there - it should be OK.


Log in to reply