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. Replace Widget in Layout
QtWS25 Last Chance

Replace Widget in Layout

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

    I have added a couple of widgets to a QFormLayout.
    Now I want to replace two widgets with two other ones (I want to replace a row).
    My application looks like this:
    !http://dl.dropbox.com/u/2346027/OldLabel.PNG(Old Label)!
    When the "change row" button is clicked, the second label should change to "New Label" and the LineEdit should change to a Combobox.

    This is how I'm trying to do it:
    @
    if(m_bToggleRow)
    {
    m_poLayout->removeWidget(m_poOldLabel);
    m_poLayout->removeWidget(m_poOldLine);
    m_poLayout->insertRow(2, m_poNewLabel, m_poNewCombo);
    m_bToggleRow = false;
    }
    else
    {
    m_poLayout->removeWidget(m_poNewLabel);
    m_poLayout->removeWidget(m_poNewCombo);
    m_poLayout->insertRow(2, m_poOldLabel, m_poOldLine);
    m_bToggleRow = true;
    }
    @

    And this is what it looks like:
    !http://dl.dropbox.com/u/2346027/NewLabel.PNG(New Label)!

    I also tried calling m_poLayout->update(), but it still looks the same.

    Is there a method to replace widgets with other ones? Or how can I do that?

    Thank you for your help!

    1 Reply Last reply
    0
    • P Offline
      P Offline
      p-himik
      wrote on last edited by
      #2

      bq. void QLayout::removeWidget ( QWidget * widget )
      Removes the widget widget from the layout. After this call, it is the caller's responsibility to give the widget a reasonable geometry or to put the widget back into a layout.
      Note: The ownership of widget remains the same as when it was added.

      The m_poOldLabel and m_poOldLine stay where m_poLayout put them, removeWidget() just removes them from layout. You should call hide() on old widgets (or delete them if you won't need them after changing the row).

      1 Reply Last reply
      0
      • E Offline
        E Offline
        ephe
        wrote on last edited by
        #3

        Thank you! This is working!

        1 Reply Last reply
        0
        • E Offline
          E Offline
          ephe
          wrote on last edited by
          #4

          I've got another question regarding the replacement of widgets.

          If I tab through the widgets, the one which was replaced is now on the last position of the tab order. Is it somehow possible to set this to the same as the one I have replaced?
          E.g. if I've replaced the widget in the second row, that the new one is still on the second position of the tab order?

          I know about setTabOrder, but I would like to know if there is another way to do it easier.

          1 Reply Last reply
          0
          • K Offline
            K Offline
            Kxyu
            wrote on last edited by
            #5

            you can try fixing it with QWidget::setTabOrder, but it can be ugly a bit

            1 Reply Last reply
            0
            • P Offline
              P Offline
              p-himik
              wrote on last edited by
              #6

              Kxyu, saho wrote about it.

              [quote author="saho" date="1320744050"]I know about setTabOrder, but I would like to know if there is another way to do it easier.[/quote]

              1 Reply Last reply
              0
              • K Offline
                K Offline
                Kxyu
                wrote on last edited by
                #7

                Missed it)

                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