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. Automatically highlight the first row of Qtreewidget?

Automatically highlight the first row of Qtreewidget?

Scheduled Pinned Locked Moved General and Desktop
c++linuxqtreewidgetitemrowhighlight
2 Posts 2 Posters 2.1k Views 2 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.
  • M Offline
    M Offline
    marlenet15
    wrote on last edited by
    #1

    I have a tree on my application and I would like it so that the first row is highlighted automatically. However, I do not want everything part of that row to be highlighted. For example:

    -fruit
    --apple
    --orange
    --pear
    -vegetable
    --carrot

    I would only like for fruit to be highlighted in the beginning. I have the following

    QTreeWidget *treeWidget = new QTreeWidget;
    QAbstractItemModel *model = treeWidget->model();
    QItemSelectionModel *selectionModel = new QItemSelectionModel(model);
    QModelIndex index = model->index(0,0); 
    selectionModel->setCurrentIndex(index, QItemSelectionModel::SelectCurrent);
    
    treeWidget->setSelectionModel(selectionModel);
    

    However, nothing happens.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You are looking for QTreeWidget::setCurrentItem

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

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