QTreeWidget я могу сохранить выбор после очистки () - PullRequest
0 голосов
/ 19 июня 2019

В настоящее время я перестраиваю свой QTreeWidget каждый раз, когда он обновляется.Проблема с этим - мой выбор выброшен.Есть ли обходной путь для этого или просто лучше найти способ обновить значения, а не перестраивать дерево?Я хотел бы сохранить выбор из предыдущего раза, когда был вызван метод.

Этот метод вызывается каждую секунду.

 void insertIntoTree(QTreeWidget *tree) {
        tree->clear();
        tree->setSelectionMode(QAbstractItemView::SingleSelection)
        for (int i = 0; i < tree.members(); i++) {
        tree->addTopLevelItem(parent);
        parent->addChild(variousData); // Re-adds all the items into the tree, this is done every iteration
   } 
//Here I would like to save something that tells which Item in the widget is selected.
}

код пользовательского интерфейса длявиджет

  <widget class="QTreeWidget" name="treeWidget">
          <property name="focusPolicy">
           <enum>Qt::ClickFocus</enum>
          </property>
          <property name="styleSheet">
           <string notr="true">QTreeView::branch:has-siblings:!adjoins-item {
    border-image: url(:/img/res/stylesheet-vline.png) 0;
}

QTreeView::branch:has-siblings:adjoins-item {
    border-image: url(:/img/res/stylesheet-branch-more.png) 0;
}

QTreeView::branch:!has-children:!has-siblings:adjoins-item {
    border-image: url(:/img/res/stylesheet-branch-end.png) 0;
}

QTreeView::branch:has-children:!has-siblings:closed,
QTreeView::branch:closed:has-children:has-siblings {
        border-image: none;
        image: url(:/img/res/stylesheet-branch-closed.png);
}

QTreeView::branch:open:has-children:!has-siblings,
QTreeView::branch:open:has-children:has-siblings  {
        border-image: none;
        image: url(:/img/res/stylesheet-branch-open.png);
}</string>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...