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. Blocking Child Widgets of Widget

Blocking Child Widgets of Widget

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 2.4k 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.
  • S Offline
    S Offline
    sandro4912
    wrote on last edited by
    #1

    Lets say I have a Widget which contains several Child Widgets in a layout.

    In the beginning I can interact with the Child Widgets . (e.g click on a Child Widgets changes there appearance),

    At some point I want to prevent that any events get send to the Child Widgets . So disable all possible interactions with the Child Widgets.

    Whats the easiest way to achieve that?

    I thought about installing an event filter into the Widget or adding a disable flag in the Child Widget which disables watching the events which is called by the Widget.

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #2

      It's not clear which events you want to block. There are a lot and blocking some of them will break your widgets, for example not handling resize event or focus events will break the look/ control flow. Not handling the paint event will break the look. There are a lot of event types. Disabling all of them is basically like hiding the widget entirely.

      Depending on what the child widgets actually are there are couple of things you could do. If you just want to disable user's interaction with these widgets there's setDisabled().
      Some widgets, like the ones handling text have a readOnly property.
      Some other widgets only handle user input when they have focus so you can change their focusPolicy to Qt::NoFocus.
      If you want to go lower level you can ignore user input by setting the window flag Qt::WindowTransparentForInput to true.

      There are probably more things you can do but you need to be more specific on what you actually want to accomplish.

      1 Reply Last reply
      4
      • S Offline
        S Offline
        sandro4912
        wrote on last edited by
        #3

        The Childs are directly derrived from QWidget and have some interactions from mouse click events.

        I want to block the evaluation of these, when the parent of them reaches a certain condition.

        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Then, like I said, you can disable those widgets and check isEnabled() in your mouse handler code or set that Qt::WindowTransparentForInput flag which will pass the events directly to whatever is under your widget.

          1 Reply Last reply
          3
          • S Offline
            S Offline
            sandro4912
            wrote on last edited by
            #5

            i tryed setWindowFlag(Qt::WindowTransparentForInput); however mouse events still get passed to the childs

            Chris KawaC 1 Reply Last reply
            0
            • S sandro4912

              i tryed setWindowFlag(Qt::WindowTransparentForInput); however mouse events still get passed to the childs

              Chris KawaC Offline
              Chris KawaC Offline
              Chris Kawa
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @sandro4912 said in Blocking Child Widgets of Widget:

              i tryed setWindowFlag(Qt::WindowTransparentForInput); however mouse events still get passed to the childs

              Ah, sorry, my mistake. Qt::WindowTransparentForInput is for windows (top level widgets). For regular children the equivalent is

              widget->setAttribute(Qt::WA_TransparentForMouseEvents);
              
              1 Reply Last reply
              2
              • S Offline
                S Offline
                sandro4912
                wrote on last edited by
                #7

                That works. I think is a better solution than iterating over all the childs and set Enabled to false;

                Pablo J. RoginaP 1 Reply Last reply
                0
                • S sandro4912

                  That works. I think is a better solution than iterating over all the childs and set Enabled to false;

                  Pablo J. RoginaP Offline
                  Pablo J. RoginaP Offline
                  Pablo J. Rogina
                  wrote on last edited by
                  #8

                  @sandro4912 said in Blocking Child Widgets of Widget:

                  That works.

                  Is your issue solved then? If so, please don't forget to mark your post as such! Thanks

                  Upvote the answer(s) that helped you solve the issue
                  Use "Topic Tools" button to mark your post as Solved
                  Add screenshots via postimage.org
                  Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                  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