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. How to check if a qwidget is closed ?
Qt 6.11 is out! See what's new in the release blog

How to check if a qwidget is closed ?

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 36.2k Views 1 Watching
  • 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    I have a parent widget A and a child widget B, and the user has the capability to open and close widget B from widget A. How can I check is widget B is closed ?

    I show widget B using the show command.

    One of the things i am thinking to do is passing a variable to the constructor of widget B then update its value in the CloseEvent, but i am pretty sure there is an easier way.

    Many thanks in advance,

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Try QWidget::isVisible()

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        You can in closeEvent() of your widget B emit your own signal widgetBClose() and then connect to this signal in widget A and do what you want in this slot.

        1 Reply Last reply
        0
        • U Offline
          U Offline
          uranusjr
          wrote on last edited by
          #4

          A closed QWidget is hidden (i.e. not visible on screen) by definition, so, as @Kxyu said, QWidget::isVisible() can indicate whether a QWidget is closed.

          QWidget::close() is basically a combination of QWidget::closeEvent(), QWidget::hide(), and QObject::deleteLater() (if Qt::WA_DeleteOnClose is set).

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            Thank you all for your responses. For isVisible, the reason why I haven't used it is as I understood from the docs if a widget is covered by another window then it is not visible. So I was confused.

            I will give it a shot and see. Let’s say a widget is open but covered by another window, would this window be visible or not ?

            Many thanks,

            1 Reply Last reply
            0
            • U Offline
              U Offline
              uranusjr
              wrote on last edited by
              #6

              Quoting the "doc of QWidget":http://doc.qt.nokia.com/stable/qwidget.html#visible-prop:

              bq. A widget that happens to be obscured by other windows on the screen is considered to be visible.

              The "covered by another widget" thing only happens with widgets which have a parent are covered by other widgets that have the same parent (quite a mouthful).

              1 Reply Last reply
              0
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #7

                Thank you uranusjr :) Much appreciated.

                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