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. Can a widget be notified if it's parent changed?
Forum Updated to NodeBB v4.3 + New Features

Can a widget be notified if it's parent changed?

Scheduled Pinned Locked Moved Solved General and Desktop
parent & childsignal & slotqdockwidget
2 Posts 1 Posters 490 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.
  • bibasmallB Offline
    bibasmallB Offline
    bibasmall
    wrote on last edited by bibasmall
    #1

    Hi all!
    I have several dock widgets in my project, all of which contain widgets that are subclasses of the same base class (this class is QWidget subclass). In this base class, I want to implement layout margins recalculation in case the parent widget is a dock widget and the dock area has been changed (via a connection to QDockWidget signal). The point is my class knows nothing about a dock widget wrapper and it needs to be notified that the parent is changed when it's put inside a dock widget to create a connection.
    There is an ugly way to achieve my needs by calling something like MyBaseClass::DockParentSet every time after QDockWidget::setWidget and create a connection in this function, but I would prefer to encapsulate this detail if possible.
    Is there an elegant way to notify a widget if its parent has changed?

    1 Reply Last reply
    0
    • bibasmallB Offline
      bibasmallB Offline
      bibasmall
      wrote on last edited by
      #2

      I was looking for

      bool MyBaseClass::event(QEvent* e)
      {
      	if (e->type() == QEvent::DynamicPropertyChange && qobject_cast<QDockWidget*>(parent())) 
      	//...
      }
      
      1 Reply Last reply
      1
      • bibasmallB bibasmall has marked this topic as solved on

      • Login

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