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. closeEvent with Multiple QDockWidgets
Forum Updated to NodeBB v4.3 + New Features

closeEvent with Multiple QDockWidgets

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 876 Views 2 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.
  • D Offline
    D Offline
    DanM
    wrote on last edited by kshegunov
    #1

    Hi! My first post here, but not my first time lurking. I've looked around for a similar thread, but haven't found anything pertaining to this issue:

    I have two DockWidgets in my AppWindow. One is a Log window, the other has some buttons and a slider. The issue is that when one of them is closed, I need to know which one was closed so I can enable re-opening it. In my code, the same closeEvent function gets called when either one is closed.
    void QDockWidget::closeEvent(QCloseEvent* event)

    Inside, closeEvent, how can I tell which DockWidget was closed?

    Thanks!

    [Moved to General and Desktop ~kshegunov]

    JonBJ 1 Reply Last reply
    0
    • D DanM

      Hi! My first post here, but not my first time lurking. I've looked around for a similar thread, but haven't found anything pertaining to this issue:

      I have two DockWidgets in my AppWindow. One is a Log window, the other has some buttons and a slider. The issue is that when one of them is closed, I need to know which one was closed so I can enable re-opening it. In my code, the same closeEvent function gets called when either one is closed.
      void QDockWidget::closeEvent(QCloseEvent* event)

      Inside, closeEvent, how can I tell which DockWidget was closed?

      Thanks!

      [Moved to General and Desktop ~kshegunov]

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @DanM
      void QDockWidget::closeEvent(QCloseEvent* event)

      This is called on the particular QDockWidget which is being closed (only), so you don't need to "tell which DockWidget was closed" (it's this)? You could override it if you want to store some permanent information on closing the dock widget.

      1 Reply Last reply
      1
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi and welcome to devnet,

        No need to go for such complex things.

        Create a View menu and add the QDockWidget::toggleViewAction of your dock widgets.

        That way everything is done for you without hassle.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        3
        • D Offline
          D Offline
          DanM
          wrote on last edited by
          #4

          I appreciate the help so far, and please forgive my ignorance since I've been working with Qt for about a month now, updating an existing app. There's currently a toolbar icon to open up the second dockwidget. The first one opens when the app starts up. A View menu is overkill for just one dockwidget.

          It's not possible for the closeEvent to know which dockwidget was closed?

          kshegunovK 1 Reply Last reply
          0
          • D DanM

            I appreciate the help so far, and please forgive my ignorance since I've been working with Qt for about a month now, updating an existing app. There's currently a toolbar icon to open up the second dockwidget. The first one opens when the app starts up. A View menu is overkill for just one dockwidget.

            It's not possible for the closeEvent to know which dockwidget was closed?

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by
            #5

            @DanM said in closeEvent with Multiple QDockWidgets:

            It's not possible for the closeEvent to know which dockwidget was closed?

            Not really, but there are (dirty) hacks. You can install an event filter to the docks to intercept from your main window/controller the close event before it's processed

            Read and abide by the Qt Code of Conduct

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Well... Why not add the action to the toolbar ? That will make both dock widgets available from there. You can then toggle them as you wish.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved