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. Qt/C++ Chaning buttons parameters in loop

Qt/C++ Chaning buttons parameters in loop

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 411 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.
  • B Offline
    B Offline
    BarbarBarabasz
    wrote on 13 Mar 2020, 12:51 last edited by
    #1

    Hello,

    For example, i have few buttons.
    Button1, Button2, Button3;
    I want changing for example visibility or disabled options in loop.
    Like in c++, when we have int array.
    for(....)
    {
    array[i] = i *5;///for example
    }

    In similar way,did i can creat array of button and changing paramters like visbility.
    For example:
    for(....)
    {
    button[i] = visibilty(false);?
    }

    Now to do similary things, i make addidional bool variable, for example visibility and i set this on false.
    Thats how look my code.
    if (visibility == false)
    {
    ui->button->setVisibility(true);
    visibility = true;
    }

    Can somebody help find better way to make my code more automaticaly and simple?

    J 1 Reply Last reply 13 Mar 2020, 13:12
    0
    • B BarbarBarabasz
      13 Mar 2020, 12:51

      Hello,

      For example, i have few buttons.
      Button1, Button2, Button3;
      I want changing for example visibility or disabled options in loop.
      Like in c++, when we have int array.
      for(....)
      {
      array[i] = i *5;///for example
      }

      In similar way,did i can creat array of button and changing paramters like visbility.
      For example:
      for(....)
      {
      button[i] = visibilty(false);?
      }

      Now to do similary things, i make addidional bool variable, for example visibility and i set this on false.
      Thats how look my code.
      if (visibility == false)
      {
      ui->button->setVisibility(true);
      visibility = true;
      }

      Can somebody help find better way to make my code more automaticaly and simple?

      J Offline
      J Offline
      JonB
      wrote on 13 Mar 2020, 13:12 last edited by JonB
      #2

      @BarbarBarabasz
      How much more simple than that do you want it to be? You put (pointers to) your widgets into an array/QList/QVector and then perform operations on them.

      If all the buttons are together and you want all of them to come & go, you could put them inside some widget to group them and then just set its visibility. But I don't know if that applies to your situation. There are also the QObject::findChild...() methods which can be used to visit, say, all pushbuttons with a common ancestor, so you don't have to put them in an array, if that is what you want.

      Now to do similary things, i make addidional bool variable, for example visibility and i set this on false.

      I don't understand what you are saying/asking here.

      B 1 Reply Last reply 13 Mar 2020, 13:56
      0
      • J JonB
        13 Mar 2020, 13:12

        @BarbarBarabasz
        How much more simple than that do you want it to be? You put (pointers to) your widgets into an array/QList/QVector and then perform operations on them.

        If all the buttons are together and you want all of them to come & go, you could put them inside some widget to group them and then just set its visibility. But I don't know if that applies to your situation. There are also the QObject::findChild...() methods which can be used to visit, say, all pushbuttons with a common ancestor, so you don't have to put them in an array, if that is what you want.

        Now to do similary things, i make addidional bool variable, for example visibility and i set this on false.

        I don't understand what you are saying/asking here.

        B Offline
        B Offline
        BarbarBarabasz
        wrote on 13 Mar 2020, 13:56 last edited by
        #3

        @JonB said in Qt/C++ Chaning buttons parameters in loop:

        to do similary things, i make addidional bool variable, for example visibility and i set this on false.

        I don't understand what you are saying/asking here.

        I create variabble bool parameter;
        I set parameter as false.

        And if i want change visibilty of buttons during cliking, i do something like this.
        if(parameter == false)
        {
        ui->button->setVisibility(true);
        parameter = true;
        }

        J 1 Reply Last reply 13 Mar 2020, 14:19
        0
        • B BarbarBarabasz
          13 Mar 2020, 13:56

          @JonB said in Qt/C++ Chaning buttons parameters in loop:

          to do similary things, i make addidional bool variable, for example visibility and i set this on false.

          I don't understand what you are saying/asking here.

          I create variabble bool parameter;
          I set parameter as false.

          And if i want change visibilty of buttons during cliking, i do something like this.
          if(parameter == false)
          {
          ui->button->setVisibility(true);
          parameter = true;
          }

          J Offline
          J Offline
          JonB
          wrote on 13 Mar 2020, 14:19 last edited by
          #4

          @BarbarBarabasz
          That seems to change one button. Anyway I don't think there is a question here.

          1 Reply Last reply
          0

          1/4

          13 Mar 2020, 12:51

          • Login

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