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

problem setting the visibility of widget.



  • i have copule of widget in ui file.
    so i use setVisible to false to hide some of them.

    then i later tried to show them by using setVisible(1) .
    but it dose not shows the widget.

    ui->calandarW->setVisible(0);
    ui->timeW->setVisible(0);
    ui->batteryW->setVisible(0);
    ui->sysW->setVisible(0);
    ui->networkW->setVisible(0);
    ui->timeW->setVisible(0);
    
    if(sm.getShowTime() == 1){//getting bool from qsetting
            ui->timeW->setVisible(1);
        }
    

    note : sure, setting is giving me true.

    i also tried this .

    //hiding all the widgets
    ui->calculatorW->setVisible(1);
    ui->calandarW->setVisible(0);
    ui->timeW->setVisible(0);
    ui->batteryW->setVisible(0);
    ui->sysW->setVisible(0);
    ui->networkW->setVisible(0);
    
    //then only showing the calculatorW
    ui->calculatorW->setVisible(1);
    

    not working. not showing the "calculatorW" widget.

    HERE IS THE CPP FILE GITHUB

    what is the problem?


  • Moderators

    @saber Is the coreaction widget visible? If it is hidden, then all of its child widgets will be hidden too.

    Note: You can replace setVisible(1) with show(), and setVisible(0) with hide().



  • @JKSH

    coreaction widget is shown on start up then after 8 second it's hidden.


  • Lifetime Qt Champion

    @saber
    Hi
    Just so we are clear. All Widgets within another widget cannot be visible
    unless the parent widget is. So there is no need to hide all children.
    You can just hide/show the parent.
    setVisible is proven to work so its something else in your code.

    Does it work if you dont try to hide anything from start ? All is shown?



  • @mrjj
    if i not hide or setVisible(0) then all the widget shows just fine.

    u could see the cpp file coreaction cpp


  • Moderators

    @saber said in problem setting the visibility of widget.:

    coreaction widget is shown on start up then after 8 second it's hidden.

    When the coreaction widget is not visible, ui->calculatorW->setVisible(1); will not make calculatorW visible.



  • i found the problem.
    i put most of the widget in battery widget.
    so if battery widget is shown most of the widget is shown.

    it happened in ui.
    silly mistake .
    sorry everyone.


Log in to reply