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. Making a widget "modal"
QtWS25 Last Chance

Making a widget "modal"

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.6k 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.
  • L Offline
    L Offline
    luxner
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andreyc
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • L Offline
        L Offline
        luxner
        wrote on last edited by
        #3

        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?

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andreyc
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • L Offline
            L Offline
            luxner
            wrote on last edited by
            #5

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

            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