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. Strange behaviour of QTreeWidget (expand/collapse)
Forum Updated to NodeBB v4.3 + New Features

Strange behaviour of QTreeWidget (expand/collapse)

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 1.4k Views
  • 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.
  • markcurlM Offline
    markcurlM Offline
    markcurl
    wrote on last edited by
    #1

    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?

    jsulmJ markcurlM 2 Replies Last reply
    0
    • markcurlM markcurl

      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?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @markcurl Shouldn't this

      QTreeWidgetItem* item( _tokensList->leafItem( pattern));
      

      be

      QTreeWidgetItem* item = new QTreeWidgetItem( _tokensList->leafItem( pattern));
      

      ?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      markcurlM 1 Reply Last reply
      0
      • jsulmJ jsulm

        @markcurl Shouldn't this

        QTreeWidgetItem* item( _tokensList->leafItem( pattern));
        

        be

        QTreeWidgetItem* item = new QTreeWidgetItem( _tokensList->leafItem( pattern));
        

        ?

        markcurlM Offline
        markcurlM Offline
        markcurl
        wrote on last edited by
        #3

        @jsulm

        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.

        jsulmJ 1 Reply Last reply
        0
        • markcurlM markcurl

          @jsulm

          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.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @markcurl OK, I see. I was confused because you don't use assignment operator to assign a value to the pointer :-)

          QTreeWidgetItem* item = _tokensList->leafItem( pattern);
          

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • markcurlM markcurl

            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?

            markcurlM Offline
            markcurlM Offline
            markcurl
            wrote on last edited by
            #5

            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 currentIndex

            
             UNSOLVED 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;
               }
            
            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