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. Redrawing Widget after replacing containing Widget

Redrawing Widget after replacing containing Widget

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 720 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.
  • ModelTechM Offline
    ModelTechM Offline
    ModelTech
    wrote on last edited by ModelTech
    #1

    I have a Widget (Parent) that has a layout in which another Widget (Child) is used. At some point, I need to replace the Child Widget by a new one and the Parent Widget needs to be redrawn. Naively, I wrote the following code as part of the Parent Widget:

    delete Child;
    Child = new ChildWidget();
    repaint();
    

    The problem is that the new Child is not drawn and instead the whole Child Widget area is no longer part of the layout. How can I solve this?

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      you have yo add the new ChildWidget to the layout. You don't need to call repaint either

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

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

        Hi,

        You're creating a new widget in the "void". You should put it in place of the old one. For example, if Child was in a layout, put the new object there.

        If you must replace it like that, why not have a "reset" function in ChildWidget ? That might be less aggressive.

        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
        • ModelTechM Offline
          ModelTechM Offline
          ModelTech
          wrote on last edited by ModelTech
          #4

          Ok, how can I get the position in the Layout of Parent widget?

          I can do a reset as in this case the new Child concerns a completely different widget...

          1 Reply Last reply
          0
          • ModelTechM Offline
            ModelTechM Offline
            ModelTech
            wrote on last edited by
            #5

            Ok guys, I found a solution thanks to your hints. I store the Layout and add the new Child after the old Child is deleted. This works perfectly well :)

            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