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. Called function when QWidget gets displayed?
Forum Updated to NodeBB v4.3 + New Features

Called function when QWidget gets displayed?

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

    Hi,

    I would like to know how I can implements some action whenever a QWidgets gets shown. For example, I have a container QWidget which contains some other QWidgets and some subclassed buttons. These buttons need to do something whenever they are displayed. (At least, the first time, they are displayed()).

    I thought that I can reimplement the show()-function since I call show() on the container widget. However, it seems that show() doesn't call show on its members like I thought it will.

    So which function can I reimplement to add some actions whenever a subclassed widget gets displayed (after being hidden or when viewed the first time.)

    Thanks!

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      When the parent widget is shown, child windows(QWidgets and subclassed buttons) are shown. You can somehow make those classes to emit signals. I'm thinking of sending some events manually immediately after calling the show. Since all these are your classes, you can implement the event handlers Or you can make some signals and connect to slots.

      e.g
      topwid.show() - This shows the all the inside buttons as well.
      QApplication::postEvent(button1,QMouseEvent(pressedEvent...));
      QApplication::postEvent(button2,QMouseEvent(pressedEvent...));
      QApplication::postEvent(button3,QMouseEvent(pressedEvent...));
      QApplication::postEvent(button3,QMouseEvent(pressedEvent...));

      All this makes button1 to emit the pressed signals.
      connect(button1,SIGNAL(pressed()),obj,SLOT(callme()));

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • R Offline
        R Offline
        RuhigBrauner
        wrote on last edited by
        #3

        Mhh,

        but there is no way to determin if show() is called on an parent widget without manually passing through signals (or normal functions)?

        I could just reimplement the show()-function to emit signals but I have to forward the signal to the buttons through all the other widgets which wouldn't realy be a nice solution. ;)
        (Well, I would have to connect everything)

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

          Hi,

          Reimplementing show() would not help since it's not a virtual function. You need to implement showEvent.

          Or maybe use an eventFilter

          Hope it helps

          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
          0
          • dheerendraD Offline
            dheerendraD Offline
            dheerendra
            Qt Champions 2022
            wrote on last edited by
            #5

            Currently there is no way to know that widget has been shown. It is guaranteed that widgets and children are shown, when the parent widget show is called. We have to do external mechanism do this. You need to some how make your widgets to emit the signal. This is only through you making them to generate signals or events. Based on this, I suggested you to fire the event. show(...) function is not virtual. It will not help there.

            Dheerendra
            @Community Service
            Certified Qt Specialist
            http://www.pthinks.com

            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