Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Solved Redrawing Widget after replacing containing Widget

    General and Desktop
    3
    5
    617
    Loading More Posts
    • 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.
    • ModelTech
      ModelTech last edited by ModelTech

      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 Reply Quote 0
      • VRonin
        VRonin last edited by

        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 Reply Quote 1
        • SGaist
          SGaist Lifetime Qt Champion last edited by

          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 Reply Quote 1
          • ModelTech
            ModelTech last edited by ModelTech

            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 Reply Quote 0
            • ModelTech
              ModelTech last edited by

              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 Reply Quote 0
              • First post
                Last post