Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Qt/C++ Chaning buttons parameters in loop



  • 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?



  • @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.



  • @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;
    }



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


Log in to reply