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. Searching bar in tree widget
QtWS25 Last Chance

Searching bar in tree widget

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt5tree widgetsearch
19 Posts 5 Posters 1.7k 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.
  • D deleted286

    @jsulm No, i dont want to select :D
    I have a search bar, it doesnt set the contains this is my problem

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

    @suslucoder said in Searching bar in tree widget:

    I have a search bar, it doesnt set the contains this is my problem

    Then can you please explain what you want to do with items you found? Because I don't understand...

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

    1 Reply Last reply
    1
    • D deleted286

      @jsulm No, i dont want to select :D
      I have a search bar, it doesnt set the contains this is my problem

      D Offline
      D Offline
      deleted286
      wrote on last edited by deleted286
      #9

      @suslucoder

      QList<QTreeWidgetItem*> arama = ui->treeWidget2->findItems(ui->ara->text(), Qt::MatchContains|Qt::MatchRecursive, 0);
          for(QTreeWidgetItem* item  : arama)
          {
            ui->treeWidget2->setCurrentItem(item, 0);  
           // item->setBackground(0, Qt::cyan);
      
          }
      

      when i comment item->setBackground(0, Qt::cyan);, unless the tree has more than 1 item that at give via ara->text, it show the exactly 1 item.

      When i un comment the

      item->setBackground(0, Qt::cyan);
      

      the code finds the every item that contains the text, but the text setCurrent item has is blue, the other one is cyan.

      When i only wrote

      item->setBackground(0, Qt::cyan);
      

      search doesnt work

      jsulmJ 1 Reply Last reply
      0
      • D deleted286

        @suslucoder

        QList<QTreeWidgetItem*> arama = ui->treeWidget2->findItems(ui->ara->text(), Qt::MatchContains|Qt::MatchRecursive, 0);
            for(QTreeWidgetItem* item  : arama)
            {
              ui->treeWidget2->setCurrentItem(item, 0);  
             // item->setBackground(0, Qt::cyan);
        
            }
        

        when i comment item->setBackground(0, Qt::cyan);, unless the tree has more than 1 item that at give via ara->text, it show the exactly 1 item.

        When i un comment the

        item->setBackground(0, Qt::cyan);
        

        the code finds the every item that contains the text, but the text setCurrent item has is blue, the other one is cyan.

        When i only wrote

        item->setBackground(0, Qt::cyan);
        

        search doesnt work

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

        @suslucoder Why do you call setCurrentItem?

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

        D 1 Reply Last reply
        0
        • jsulmJ jsulm

          @suslucoder Why do you call setCurrentItem?

          D Offline
          D Offline
          deleted286
          wrote on last edited by
          #11

          @jsulm yes i dont i know why im using it.
          I saw in somewehere.
          But when i delete it, it doesnt work

          jsulmJ 1 Reply Last reply
          0
          • D deleted286

            @jsulm yes i dont i know why im using it.
            I saw in somewehere.
            But when i delete it, it doesnt work

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

            @suslucoder said in Searching bar in tree widget:

            But when i delete it, it doesnt work

            In what way it doesn't work? setBackground should work without setCurrentItem, they are unrelated.

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

            D 1 Reply Last reply
            0
            • jsulmJ jsulm

              @suslucoder said in Searching bar in tree widget:

              But when i delete it, it doesnt work

              In what way it doesn't work? setBackground should work without setCurrentItem, they are unrelated.

              D Offline
              D Offline
              deleted286
              wrote on last edited by
              #13

              @jsulm when i delete

              ui->treeWidget2->setCurrentItem(item, 0);
              

              the hole code doesnt work. without any error messages

              D 1 Reply Last reply
              0
              • D deleted286

                @jsulm when i delete

                ui->treeWidget2->setCurrentItem(item, 0);
                

                the hole code doesnt work. without any error messages

                D Offline
                D Offline
                deleted286
                wrote on last edited by
                #14

                @suslucoder I debug and, it finds the items but doesnt show me on tree widget

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

                  Hi,

                  Why don't you just modify the background of each item of the list and nothing else ?

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

                  D 1 Reply Last reply
                  0
                  • nageshN Offline
                    nageshN Offline
                    nagesh
                    wrote on last edited by
                    #16

                    @suslucoder said in Searching bar in tree widget:

                    When i only wrote
                    item->setBackground(0, Qt::cyan);

                    search doesnt work

                    I think arguement for setBackground is QBrush not the color
                    void QTreeWidgetItem::setBackground(int column, const QBrush &brush)

                    1 Reply Last reply
                    0
                    • Christian EhrlicherC Offline
                      Christian EhrlicherC Offline
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on last edited by
                      #17

                      @nagesh said in Searching bar in tree widget:

                      I think arguement for setBackground is QBrush not the color

                      Can you please elaborate this?
                      https://doc.qt.io/qt-5/qbrush.html#QBrush-3

                      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                      Visit the Qt Academy at https://academy.qt.io/catalog

                      1 Reply Last reply
                      1
                      • SGaistS SGaist

                        Hi,

                        Why don't you just modify the background of each item of the list and nothing else ?

                        D Offline
                        D Offline
                        deleted286
                        wrote on last edited by
                        #18

                        @SGaist when i modify the background, for highligting the searching items,
                        even the text was changed, it keep the oldest item.

                        I search for a and highligh its background.
                        Then i delete a, search for b

                        It shows me the both a and b

                        1 Reply Last reply
                        0
                        • nageshN Offline
                          nageshN Offline
                          nagesh
                          wrote on last edited by
                          #19

                          @Christian-Ehrlicher thanks for the correction.

                          @suslucoder it's showing old search items with different color because you have set it's background color in last search..
                          It's better to set all with default color and matched items in highlight colour for each search

                          1 Reply Last reply
                          2

                          • Login

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