Problems with Open-Source Downloads read https://www.qt.io/blog/problem-with-open-source-downloads and https://forum.qt.io/post/638946

Making a widget "modal"



  • Hi,
    I have a mainwindow which has a progressbar and an "abort" button at its bottom. The progressbar shows the progress of a task running in a thread, the button should allow the user to cancel the current task. Furthermore I do not want that the user can interact with the remaining mainwindow while the task is running, i.e. only the "abort" button should be "clickable".
    So it should basically mimic the behavior of a modal progressDialog, but without opening a new window.

    What would be the best way to achieve this behavior?

    Thanks for your ideas,
    Mathias



  • Disable all controls except "Cancel" before you start long-running thread. Enable everything after "Cancel" or when thread is done.

    So you will have two states. An "init" state when all controls except "cancel" are enabled and thread is not running. Second state is "running" state when all controls except "cancel" are disabled and the tread is running.
    Transition from "init" to "running" is done by pressing "Start", transition from "running" to "init" is done by "cancel" or thread done.
    You can have one more state "canceling" if you need to do something to cleanup on "cancel"

    You can do it using "state machine":http://qt-project.org/doc/qt-5/statemachine-api.html

    Or implement all that logic in a set of if or switch statements if Qt state machine is too heavy for your application.



  • Hi,
    I was already thinking about something like that. The problem that I have is, that the GUI is quite complex, i.e. the button that I want to "keep enabled" is nested within many other parent widgets, i.e. at that point I do not know all the parents and their children to disable one by one.
    E.g. if my "cancel" button is a children of a GroupBox and that Groupbox also contains other widgets which I want to disable I cannot simply
    groupbox->setDisabled(true)
    cancelButton->setEnabled(true)
    because cancelButton cannot be enabled within a disabled parent, right?



  • Looks like you are right. It is not possible to enable child under disabled parent.
    Thanks for pointing it out. I will have to solve the same problem soon :-)
    It means that you may need to create a controller that will enable disable the controls individually.



  • ok, I solved it by moving the progresswidget at the level of the centralwidget. this way I can disable all other child-widgets.


Log in to reply