Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to select multiple checkboxes
Qt 6.12 LTS is out! See what's new in the release blog

How to select multiple checkboxes

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 1.3k 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 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
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 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 last edited by
        #3

        you mean third party lib like libevdev?

        Christian EhrlicherC 1 Reply Last reply
        0
        • J JacobNovitsky

          you mean third party lib like libevdev?

          Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 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 last edited by
            #5

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

            Christian EhrlicherC 1 Reply Last reply
            0
            • J JacobNovitsky

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

              Christian EhrlicherC Online
              Christian EhrlicherC Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 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 last edited by
                #7

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

                1 Reply Last reply
                0
                • VRoninV Offline
                  VRoninV Offline
                  VRonin
                  wrote on 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

                  • Login

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