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. layout->removeWidget(QWidget*) not working correctly

layout->removeWidget(QWidget*) not working correctly

Scheduled Pinned Locked Moved Solved General and Desktop
c++qt 5.9.5qlayout
3 Posts 2 Posters 1.5k 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.
  • D Offline
    D Offline
    Daniel_Contro
    wrote on 2 Sept 2020, 09:23 last edited by
    #1

    Hi to everyone,
    I'm developing an application which has different custom widgets. In particulate I have derived the QScrollArea widget for adding my own widgets to it. So far I can easily add widgets to it, but when it comes to deleting a widget it's kinda buggy, half of the widget disappear, but the remaining half is still visible and interactive. The following is my current code:

    void TasksList::removeTask(const unsigned short taskId) {
      auto children = _layout->children();
      for (auto i = 0; i < _layout->count(); i++) {
        TaskPreview* tmp = dynamic_cast<TaskPreview*>(_layout->itemAt(i)->widget());
        if (tmp && (tmp->getId() == taskId)) {
          _layout->removeWidget(tmp);
        }
      }
    }
    

    I should also point out that _layout is a pointer to the QScrollArea's associated widget layout.

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Bonnie
      wrote on 2 Sept 2020, 09:26 last edited by
      #2

      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 or to explicitly hide it if necessary.

      If you don't need the removed widget anymore, don't forget to delete it.

      1 Reply Last reply
      2
      • D Offline
        D Offline
        Daniel_Contro
        wrote on 2 Sept 2020, 09:36 last edited by
        #3

        Thank you, I actually commented out the delete because I wasn't sure of the removeWidget behaviour, now it works flawlessly

        1 Reply Last reply
        0

        1/3

        2 Sept 2020, 09:23

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved