Strange behaviour of QTreeWidget (expand/collapse)
-
Dear All,
after the migration from Qt4 to Qt5 the following code seems to work not any longer.
//_tokenList = QTreeWidget QTreeWidgetItem* item( _tokensList->leafItem( pattern)); if( item != nullptr) { _tokensList->collapseAll(); _tokensList->setCurrentItem( item); return; }
After selecting a token the Tree should completely collaps and with setCurrentItem re-expanded to the node. Sometimes this is working fine but often the tree remains collapsed.
Does anybody have an idea why this happen?Could it be possible that there are some problems with compressed postEvents?
-
Dear All,
after the migration from Qt4 to Qt5 the following code seems to work not any longer.
//_tokenList = QTreeWidget QTreeWidgetItem* item( _tokensList->leafItem( pattern)); if( item != nullptr) { _tokensList->collapseAll(); _tokensList->setCurrentItem( item); return; }
After selecting a token the Tree should completely collaps and with setCurrentItem re-expanded to the node. Sometimes this is working fine but often the tree remains collapsed.
Does anybody have an idea why this happen?Could it be possible that there are some problems with compressed postEvents?
-
@markcurl Shouldn't this
QTreeWidgetItem* item( _tokensList->leafItem( pattern));
be
QTreeWidgetItem* item = new QTreeWidgetItem( _tokensList->leafItem( pattern));
?
-
No, _tokensList is derived from Qtreewidget and the function leafItem(pattern) returns a QtreeWidgetItem* to the item inside the tree which matchs the pattern. There is no need to call the constructor of QTreeWidgetItem.
-
Dear All,
after the migration from Qt4 to Qt5 the following code seems to work not any longer.
//_tokenList = QTreeWidget QTreeWidgetItem* item( _tokensList->leafItem( pattern)); if( item != nullptr) { _tokensList->collapseAll(); _tokensList->setCurrentItem( item); return; }
After selecting a token the Tree should completely collaps and with setCurrentItem re-expanded to the node. Sometimes this is working fine but often the tree remains collapsed.
Does anybody have an idea why this happen?Could it be possible that there are some problems with compressed postEvents?
I have found the problem. The QTreeWidget expands to the item only, if the new currentIndex is presented in another node as the old currentIndex.
Solution: reset currentIndexUNSOLVED Strange behaviour of QTreeWidget (expand/collapse) markcurl Bookmark 0 0 Reply Dear All, after the migration from Qt4 to Qt5 the following code seems to work not any longer. //_tokenList = QTreeWidget QTreeWidgetItem* item( _tokensList->leafItem( pattern)); if( item != nullptr) { _tokensList->setCurrentItem( nullptr); _tokensList->collapseAll(); _tokensList->setCurrentItem( item); return; }