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. How to replace widget without creating object
Forum Updated to NodeBB v4.3 + New Features

How to replace widget without creating object

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 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.
  • D Offline
    D Offline
    Dimple
    wrote on last edited by Dimple
    #1

    hi ,,,anyone please help me to solve it
    To Replace parentwidget i used this code

        mainpage*  mn = new mainpage(ui->widget->parentWidget());
        ui->widget->parentWidget()->layout()->replaceWidget(ui->widget,mn->ui->widget);
        ui->widget=mn->ui->widget;
        ui->widget= mn;
    

    To replace parentwidget many times i created object so issue is 6 times created objects to mainpage class in another classes so when I Integrate BusyCall() API (when i click on Call Tab(call button) ,QMessageBox are showing 6 times),,,on QMessageBox i added one toast message i.e."busy in another call"

    jsulmJ 1 Reply Last reply
    0
    • D Dimple

      hi ,,,anyone please help me to solve it
      To Replace parentwidget i used this code

          mainpage*  mn = new mainpage(ui->widget->parentWidget());
          ui->widget->parentWidget()->layout()->replaceWidget(ui->widget,mn->ui->widget);
          ui->widget=mn->ui->widget;
          ui->widget= mn;
      

      To replace parentwidget many times i created object so issue is 6 times created objects to mainpage class in another classes so when I Integrate BusyCall() API (when i click on Call Tab(call button) ,QMessageBox are showing 6 times),,,on QMessageBox i added one toast message i.e."busy in another call"

      jsulmJ Online
      jsulmJ Online
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Dimple Why do you want to replace parent widget? Can you explain better your use case?
      And parent widget must be an existing object - how else can it be a parent?
      I don't know what your use case is, but what is this new parent widget supposed to be?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Dimple
        wrote on last edited by
        #3

        Already mainpage has one widget(parent widget) ,,i want to replace mainpage to show another page(another class widget) i mean child widget ,,,
        ex: you are using whatsapp ryt ,,,if you want to make call to ur friend ,you will click on audio button(call button) then u get outgoing page (shows outgoing call page ) so to show outgoing call page(child widget)instead of parent widget page ,,

        mrjjM 1 Reply Last reply
        0
        • D Dimple

          Already mainpage has one widget(parent widget) ,,i want to replace mainpage to show another page(another class widget) i mean child widget ,,,
          ex: you are using whatsapp ryt ,,,if you want to make call to ur friend ,you will click on audio button(call button) then u get outgoing page (shows outgoing call page ) so to show outgoing call page(child widget)instead of parent widget page ,,

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Dimple
          Hi
          For such design, the StackedWidget is very good
          http://doc.qt.io/qt-5/qstackedwidget.html
          It allows you to have some pages and flip between them.

          1 Reply Last reply
          2
          • D Offline
            D Offline
            Dimple
            wrote on last edited by Dimple
            #5

            yeah you are ryt but now have to continue this only ,,,my senior gave one solution for this that is ,,
            0_1545318253454_Screenshot_2018-12-20-20-19-43-558_com.skype.raider.png

            if u knw how to create child widget ? suggest me please

            mrjjM 1 Reply Last reply
            0
            • D Dimple

              yeah you are ryt but now have to continue this only ,,,my senior gave one solution for this that is ,,
              0_1545318253454_Screenshot_2018-12-20-20-19-43-558_com.skype.raider.png

              if u knw how to create child widget ? suggest me please

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Dimple
              Ok, thats sad as StackedWidget does exactly what u need and ensure you oly create main and sub widgets once.
              Anyway, you seem to try to replace with a widget inside another UI.
              Is that widget in a layout ?

              1 Reply Last reply
              0
              • D Offline
                D Offline
                Dimple
                wrote on last edited by
                #7

                yeah,,,that widget in a layout

                mrjjM 1 Reply Last reply
                0
                • D Dimple

                  yeah,,,that widget in a layout

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Dimple
                  That means the layout owns that other widget and im not sure replaceWidget will handle that correctly.
                  You can use http://doc.qt.io/qt-5/qlayout.html#takeAt
                  To remove the Other widget from its layout first, then
                  replaceWidget should work.

                  However, this is a very bad way and will take tons of house keeping if you plan to go back and forth between the pages.

                  Using StackedWidget would just work and ensure the sub widgets only be created once.

                  1 Reply Last reply
                  1
                  • D Offline
                    D Offline
                    Dimple
                    wrote on last edited by
                    #9

                    @mrji
                    server is down ,, i ll check it out 2morrow morn & let u knw
                    Thanks

                    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