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?
Forum Updated to NodeBB v4.3 + New Features

Automatically highlight the first row of Qtreewidget?

Scheduled Pinned Locked Moved General and Desktop
c++linuxqtreewidgetitemrowhighlight
2 Posts 2 Posters 1.9k 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 29 Sept 2015, 16:05 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
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 29 Sept 2015, 20:42 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

      1/2

      29 Sept 2015, 16:05

      • Login

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