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 can i remove a widget from QSplitter?
QtWS25 Last Chance

How can i remove a widget from QSplitter?

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

    I've tried the QSplitter::hide(),show(),update function, also delete QWidget.
    Nothing work.

    @void PlainView::addComponent(QWidget *widget)
    {
    qDebug() << _splitOne->widget(1);

    //delete current widget on index 1
    delete _splitOne->widget(1);
    //add new widget on index 1
    _splitOne->addWidget(widget);

    qDebug() << _splitOne->widget(1);
    }

    //output
    QObject(0x0)
    QTextEdit(0xa0f580@

    Thats okey, but i can't see the new widget. Some People told me, try this:
    @_splitOne->widget(1)->setParent(NULL)@ or @_splitOne->widget(1)->setParent(0);@ But my program throw an exception:
    @The program has unexpectedly finished.@

    How can i delete the widget / see the new widget ?

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi, welcome to devnet.

      Have a look at these examples:
      @
      QString nextName() {
      static int index = 0;
      return QString("Label ") + QString::number(index++);
      }

      void MainWindow::on_pushButtonAddFirst_clicked() {
      ui->splitter->insertWidget(0, new QLabel(nextName(), this));
      }

      void MainWindow::on_pushButtonAddLast_clicked() {
      ui->splitter->addWidget(new QLabel(nextName(), this));
      }

      void MainWindow::on_pushButtonRemoveFirst_clicked() {
      if(ui->splitter->count() > 0)
      ui->splitter->widget(0)->deleteLater();
      }

      void MainWindow::on_pushButtonRemoveLast_clicked() {
      if(ui->splitter->count() > 0)
      ui->splitter->widget(ui->splitter->count() -1)->deleteLater();
      }
      @

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kiesxx
        wrote on last edited by
        #3

        here is my solution:

        @ if(splitter->widget(widgetPos)){
        // remove widget from splitter
        QWidget *oldWidget = splitter->widget(widgetPos);
        // remove parent of the widget from the gui
        oldWidget->setParent(0);
        // delete current widget on index 1
        oldWidget->deleteLater();
        }
        splitter->insertWidget(widgetPos, widget);@

        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