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

Searching Button Text

Scheduled Pinned Locked Moved Solved General and Desktop
epiales666
39 Posts 3 Posters 10.3k 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.
  • A ambershark

    @Epiales666 Ok, so to fix your slot definition just change this line in your header file:

    private slots:
       void MainWindow::on_lineEdit_textChanged();
    

    to be:

    private slots:
       void on_lineEdit_textChanged(const QString &);
    

    As for the findChildren, everything looks good there, so after you fix this above error give me a full build log with errors in it.

    Epiales666E Offline
    Epiales666E Offline
    Epiales666
    wrote on last edited by Epiales666
    #29

    @ambershark

    So frustrating.... every where on google I've searched, that line is correctly written... but it throws that error.... grrrr

     QList<QPushButton *> buttons = findChildren<QPushButton *>();
    

    The Syntax Error: '>'

    What a mess lol....

    Be Blessed!
    Epiales666

    1 Reply Last reply
    0
    • A ambershark

      @Epiales666 Ok, I fixed the code tags for you, the 3 ticks at the "end" needed to be on their own line.

      I'll take a look and see what's going on.

      Epiales666E Offline
      Epiales666E Offline
      Epiales666
      wrote on last edited by
      #30

      @ambershark

      HAHA, I'm always messing with stuff. I've been removing and editing now for like an hour or more. I have it working. I removed the void findChildren(); from the header and it worked. lol....

      only issue is, it still shows the EMPTY buttons instead of removing them. Yeah, it removes the text and hides it, but in order to get to the exe that it's searching, I must scroll down to get to it.

      I'm assuming it's coded to just remove the text...not the buttons?

      Anyway.. thank you very much hon, and sorry for being difficult.

      Be Blessed!
      Epiales666

      1 Reply Last reply
      0
      • A ambershark

        Ok here ya go, this function should do what you need:

        void MainWindow::on_lineEdit_textChanged(const QString &search)
        {
            QList<QPushButton *> buttons = findChildren<QPushButton *>();
        
            // handle empty search by showing all buttons and exiting
            if (search.isEmpty())
            {
                foreach (QPushButton *b, buttons)
                    b->show();
        
                return;
            }
        
            // search buttons for any matching "search" and hide everything not matching
            foreach (QPushButton *b, buttons)
            {
                if (b->text().contains(search, Qt::CaseInsensitive))
                    b->show();
                else
                    b->hide();
            }
        }
        
        Epiales666E Offline
        Epiales666E Offline
        Epiales666
        wrote on last edited by
        #31

        @ambershark

        Sorry, my misinformation. It's removing the buttons, but showing the icons. That is why I"m having to scroll down to get to the program. I'm going to try and write something to remove the icons as well. Wish me luck. If you feel generous, maybe you can help me get that done :)

        You are GREAT.. So thank you very much. This is what it looks like when I search for something at the bottom of the window lol...

        https://gyazo.com/1d5e0ac17d6fb50d9343c456dfd34db4

        Be Blessed!
        Epiales666

        1 Reply Last reply
        0
        • A ambershark

          Ok here ya go, this function should do what you need:

          void MainWindow::on_lineEdit_textChanged(const QString &search)
          {
              QList<QPushButton *> buttons = findChildren<QPushButton *>();
          
              // handle empty search by showing all buttons and exiting
              if (search.isEmpty())
              {
                  foreach (QPushButton *b, buttons)
                      b->show();
          
                  return;
              }
          
              // search buttons for any matching "search" and hide everything not matching
              foreach (QPushButton *b, buttons)
              {
                  if (b->text().contains(search, Qt::CaseInsensitive))
                      b->show();
                  else
                      b->hide();
              }
          }
          
          Epiales666E Offline
          Epiales666E Offline
          Epiales666
          wrote on last edited by
          #32

          @ambershark

          Aha lol... I figured out how to remove the labels as well. I"m a fast learner once I get the code lol...

          Now, having the results appear at the top is the last thing. Right now they appear in the middle. It might just be as easy as aligning the scroll area, so I'll mess with it. Thank you again. I'll let you know what I come up with. YAY YOU...thx hon

          Be Blessed!
          Epiales666

          1 Reply Last reply
          0
          • A ambershark

            @Epiales666 Ok, I fixed the code tags for you, the 3 ticks at the "end" needed to be on their own line.

            I'll take a look and see what's going on.

            Epiales666E Offline
            Epiales666E Offline
            Epiales666
            wrote on last edited by Epiales666
            #33

            @ambershark

            Okay hon... my last reply to you lol. I get excited when things work out and work properly :D

            This is what it looks like when I search.

            https://gyazo.com/a28eacded4f5faa1861062dde5fc6c20

            Now I have aligned the actual scroll area to be aligned to the top and the left, but that didn't work. Just need to figure out how to put the searched items at the top and not separated. Any ideas? If u're tired of me, no worries, I"ll figure it out, or make it work as is. You've been extremely wonderful. Thank you and the other guy...

            ---------{@ X Eternity

            Be Blessed!
            Epiales666

            A 1 Reply Last reply
            1
            • Epiales666E Epiales666

              @ambershark

              Okay hon... my last reply to you lol. I get excited when things work out and work properly :D

              This is what it looks like when I search.

              https://gyazo.com/a28eacded4f5faa1861062dde5fc6c20

              Now I have aligned the actual scroll area to be aligned to the top and the left, but that didn't work. Just need to figure out how to put the searched items at the top and not separated. Any ideas? If u're tired of me, no worries, I"ll figure it out, or make it work as is. You've been extremely wonderful. Thank you and the other guy...

              ---------{@ X Eternity

              A Offline
              A Offline
              ambershark
              wrote on last edited by
              #34

              @Epiales666 Hmm, did you try setAlignment(Qt::AlignHCenter | Qt::AlignTop); ?

              I don't work with scroll areas much but that alignment should do it. It could be from hiding and showing those labels and buttons that is causing it to act weird. Not necessarily the best solution but it should work. :)

              Also if you make a custom class for your buttons that can handle the picture and the button then you wouldn't need to hide/show them separately since it would just be one object. Something for a later time once you learn a bit more. :)

              My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

              Epiales666E 2 Replies Last reply
              1
              • A ambershark

                @Epiales666 Hmm, did you try setAlignment(Qt::AlignHCenter | Qt::AlignTop); ?

                I don't work with scroll areas much but that alignment should do it. It could be from hiding and showing those labels and buttons that is causing it to act weird. Not necessarily the best solution but it should work. :)

                Also if you make a custom class for your buttons that can handle the picture and the button then you wouldn't need to hide/show them separately since it would just be one object. Something for a later time once you learn a bit more. :)

                Epiales666E Offline
                Epiales666E Offline
                Epiales666
                wrote on last edited by
                #35

                @ambershark said in Searching Button Text:

                setAlignment(Qt::AlignHCenter | Qt::AlignTop);

                yeah, I've been working on it since I talked to you last. Haven't taken a break, and havn't figured anything out lmao...

                When I put the above in the cpp, I get this:

                C:\Users\dclar.DESKTOP-JTNNAGR\Desktop\test\ApplicationPicker\mainwindow.cpp:200: error: C3861: 'setAlignment': identifier not found

                Be Blessed!
                Epiales666

                A 1 Reply Last reply
                0
                • Epiales666E Epiales666

                  @ambershark said in Searching Button Text:

                  setAlignment(Qt::AlignHCenter | Qt::AlignTop);

                  yeah, I've been working on it since I talked to you last. Haven't taken a break, and havn't figured anything out lmao...

                  When I put the above in the cpp, I get this:

                  C:\Users\dclar.DESKTOP-JTNNAGR\Desktop\test\ApplicationPicker\mainwindow.cpp:200: error: C3861: 'setAlignment': identifier not found

                  A Offline
                  A Offline
                  ambershark
                  wrote on last edited by ambershark
                  #36

                  @Epiales666 Well you need your scroll area object... I don't know what it's called but I'll assume it's in your ui variable... let's just say ui->myScrollArea->setAlignment(...) that should help you. Of course replace it with the actual variable. :)

                  You could probably set that in designer too somewhere. I'm not sure though I don't really use the designer. I tend to just write the code by hand.

                  My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                  Epiales666E 2 Replies Last reply
                  1
                  • A ambershark

                    @Epiales666 Well you need your scroll area object... I don't know what it's called but I'll assume it's in your ui variable... let's just say ui->myScrollArea->setAlignment(...) that should help you. Of course replace it with the actual variable. :)

                    You could probably set that in designer too somewhere. I'm not sure though I don't really use the designer. I tend to just write the code by hand.

                    Epiales666E Offline
                    Epiales666E Offline
                    Epiales666
                    wrote on last edited by
                    #37

                    @ambershark

                    Makes sense... it's just scrollArea.. and I added but it doesn't actually do anything. There are no errors, but it doesn't work ... Story of my life LOL... Thanks Hon... I'm still a chuggin along working on it. :)

                    Be Blessed!
                    Epiales666

                    1 Reply Last reply
                    0
                    • A ambershark

                      @Epiales666 Well you need your scroll area object... I don't know what it's called but I'll assume it's in your ui variable... let's just say ui->myScrollArea->setAlignment(...) that should help you. Of course replace it with the actual variable. :)

                      You could probably set that in designer too somewhere. I'm not sure though I don't really use the designer. I tend to just write the code by hand.

                      Epiales666E Offline
                      Epiales666E Offline
                      Epiales666
                      wrote on last edited by
                      #38

                      @ambershark

                      I have tried this:

                      ui->scrollArea->setAlignment(Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop);
                      

                      Maybe it's a scroll area thing. I have no idea why it won't work.

                      Be Blessed!
                      Epiales666

                      1 Reply Last reply
                      0
                      • A ambershark

                        @Epiales666 Hmm, did you try setAlignment(Qt::AlignHCenter | Qt::AlignTop); ?

                        I don't work with scroll areas much but that alignment should do it. It could be from hiding and showing those labels and buttons that is causing it to act weird. Not necessarily the best solution but it should work. :)

                        Also if you make a custom class for your buttons that can handle the picture and the button then you wouldn't need to hide/show them separately since it would just be one object. Something for a later time once you learn a bit more. :)

                        Epiales666E Offline
                        Epiales666E Offline
                        Epiales666
                        wrote on last edited by
                        #39

                        @ambershark

                        Okay... I had the stuff snapped to the mainwindows grid, so that's why I couldn't align it properly. I rewrote the entire thing and it works now. At least mostly. Some items will show in the middle, while most of them show at the top. Not sure why it does that, but it's workable.

                        And about the labels? When I do a search/filter on the labels, along with the buttons, they show up just fine without any issues. But once I put a picture in the label, they don't show anymore. Not sure why that would have anything to do with it, since it's still considered a QLabel...

                        Anyway, it works as good as I can get it I think. Thank you so very much for your help.

                        Be Blessed!
                        Epiales666

                        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