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. QTreeWidget setCurrentIndex
Qt 6.11 is out! See what's new in the release blog

QTreeWidget setCurrentIndex

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 455 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.
  • Q Offline
    Q Offline
    qt.1234
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      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.

      (Z(:^

      1 Reply Last reply
      4

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved