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 increment the number of pushbutton

how to increment the number of pushbutton

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 564 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.
  • sankarapandiyanS Offline
    sankarapandiyanS Offline
    sankarapandiyan
    wrote on last edited by sankarapandiyan
    #1

    I tried like this but x is not fixed there properly ..
    here data =6

         for (samplerange = 1 ; samplerange <= data  ; samplerange++)
         {         
             QString x[6] = {"pushButton_100","pushButton_101","pushButton_102","pushButton_103","pushButton_104","pushButton_105"};
    
             ui->x[counter++].setStyleSheet(QString("QPushButton {background-color: red;}"));
         }
    }
    

    I want to increment the pushbutton number in code
    like this

    
    pushButton_100 = button;
         for (samplerange = 1 ; samplerange <= data  ; samplerange++)
         {         
                  ui->pushButton_100->setStyleSheet(QString("QPushButton {background-color: red;}"));
         }
    } button++;
    
    
    jsulmJ 1 Reply Last reply
    0
    • sankarapandiyanS sankarapandiyan

      I tried like this but x is not fixed there properly ..
      here data =6

           for (samplerange = 1 ; samplerange <= data  ; samplerange++)
           {         
               QString x[6] = {"pushButton_100","pushButton_101","pushButton_102","pushButton_103","pushButton_104","pushButton_105"};
      
               ui->x[counter++].setStyleSheet(QString("QPushButton {background-color: red;}"));
           }
      }
      

      I want to increment the pushbutton number in code
      like this

      
      pushButton_100 = button;
           for (samplerange = 1 ; samplerange <= data  ; samplerange++)
           {         
                    ui->pushButton_100->setStyleSheet(QString("QPushButton {background-color: red;}"));
           }
      } button++;
      
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @sankarapandiyan What is ui->x?!
      Can you please explain more clearly what you're trying to do?
      The code you posted does not make sense to be honest and is not even valid.

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

      sankarapandiyanS 1 Reply Last reply
      0
      • jsulmJ jsulm

        @sankarapandiyan What is ui->x?!
        Can you please explain more clearly what you're trying to do?
        The code you posted does not make sense to be honest and is not even valid.

        sankarapandiyanS Offline
        sankarapandiyanS Offline
        sankarapandiyan
        wrote on last edited by sankarapandiyan
        #3

        @jsulm
        If i give data = 6 as a input , so after that the 6 pushbutton need to highlight with red colour , Pb_1 ,pb_2 to upto Pb_6...
        for this purpose i am using the for loop and tried to increment the Pb++ (pushbutton increment).

        So i wrote the code like this

        
        pb_1 = button;
             for (samplerange = 1 ; samplerange <= data  ; samplerange++)
             {         
                      ui->pb_1 ->setStyleSheet(QString("QPushButton {background-color: red;}"));
             }
        } button++;
        

        But its not a good idea . say me some suggestions

        jsulmJ 1 Reply Last reply
        0
        • sankarapandiyanS sankarapandiyan

          @jsulm
          If i give data = 6 as a input , so after that the 6 pushbutton need to highlight with red colour , Pb_1 ,pb_2 to upto Pb_6...
          for this purpose i am using the for loop and tried to increment the Pb++ (pushbutton increment).

          So i wrote the code like this

          
          pb_1 = button;
               for (samplerange = 1 ; samplerange <= data  ; samplerange++)
               {         
                        ui->pb_1 ->setStyleSheet(QString("QPushButton {background-color: red;}"));
               }
          } button++;
          

          But its not a good idea . say me some suggestions

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

          @sankarapandiyan This is not valid C++ code.
          If you want to iterate over your buttons in a loop then put pointers to these buttons into a QVector:

          QVector<QPushButton*> buttons;
          buttons->append(new QPushButton());
          ...
          
          for (int i = 0; i < buttons.size(); ++i) {
              buttons[i] ->...
          }
          

          This code is just to show how to do it, adapt it to your needs.

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

          sankarapandiyanS 1 Reply Last reply
          3
          • jsulmJ jsulm

            @sankarapandiyan This is not valid C++ code.
            If you want to iterate over your buttons in a loop then put pointers to these buttons into a QVector:

            QVector<QPushButton*> buttons;
            buttons->append(new QPushButton());
            ...
            
            for (int i = 0; i < buttons.size(); ++i) {
                buttons[i] ->...
            }
            

            This code is just to show how to do it, adapt it to your needs.

            sankarapandiyanS Offline
            sankarapandiyanS Offline
            sankarapandiyan
            wrote on last edited by
            #5

            @jsulm thanks a lot

            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