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. How to select multiple checkboxes
Forum Updated to NodeBB v4.3 + New Features

How to select multiple checkboxes

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 416 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.
  • J Offline
    J Offline
    JacobNovitsky
    wrote on 18 Sept 2024, 14:09 last edited by
    #1

    I have checkboxes stacked together
    checkbox_1
    ...
    checkbox_9
    I want to be able to select some with something like this
    click to checkbox_1
    press shift
    click to checkbox_9

    all checkboxes selected

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 18 Sept 2024, 14:51 last edited by
      #2

      You have to implement such a logic by yourself.

      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
      • J Offline
        J Offline
        JacobNovitsky
        wrote on 18 Sept 2024, 15:05 last edited by
        #3

        you mean third party lib like libevdev?

        C 1 Reply Last reply 18 Sept 2024, 15:07
        0
        • J JacobNovitsky
          18 Sept 2024, 15:05

          you mean third party lib like libevdev?

          C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 18 Sept 2024, 15:07 last edited by
          #4

          @JacobNovitsky said in How to select multiple checkboxes:

          you mean third party lib like libevdev?

          I don't see why you would need this for such a simple task - but do what you want.

          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
          • J Offline
            J Offline
            JacobNovitsky
            wrote on 18 Sept 2024, 15:07 last edited by
            #5

            For sure I would use any another more simple variant
            what is your suggestion?

            C 1 Reply Last reply 18 Sept 2024, 15:10
            0
            • J JacobNovitsky
              18 Sept 2024, 15:07

              For sure I would use any another more simple variant
              what is your suggestion?

              C Offline
              C Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 18 Sept 2024, 15:10 last edited by
              #6

              @JacobNovitsky said in How to select multiple checkboxes:

              what is your suggestion?

              For what? Checking if a key is pressed?

              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
              0
              • J Offline
                J Offline
                JacobNovitsky
                wrote on 18 Sept 2024, 15:33 last edited by
                #7

                No, I need to select 10 check boxes with one click using SHIFT

                1 Reply Last reply
                0
                • V Offline
                  V Offline
                  VRonin
                  wrote on 18 Sept 2024, 15:55 last edited by VRonin
                  #8

                  It's FAR from perfect but should be something like this

                  private:
                  int lastPressedCBox = -1;
                  QList<QCheckBox*> checkBoxesContainer;
                  
                  for(int i=0;i<checkBoxesContainer.size();++i)
                  QObject::connect(checkBoxesContainer.at(i), QCheckBox::clicked,[i,this](){
                      if(lastPressedCBox>=0 && QGuiApplication::queryKeyboardModifiers() & Qt::ShiftModifier){
                          for(j=std::min(i,lastPressedCBox);j<=std::max(i,lastPressedCBox);++j)
                              checkBoxesContainer.at(j)->setCheckState(checkBoxesContainer.at(std::min(i,lastPressedCBox)).checkState());
                      }
                      lastPressedCBox=i;
                  });
                  

                  "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                  ~Napoleon Bonaparte

                  On a crusade to banish setIndexWidget() from the holy land of Qt

                  1 Reply Last reply
                  1

                  3/8

                  18 Sept 2024, 15:05

                  5 unread
                  • Login

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