If a QSplitter contains only one widget, or only one visible widget, then the splitter handle is not shown. The QSplitter still exists, and can have widgets re-added. Watch this for 10 seconds:
#include <QtGui>
#include <QDebug>
Q_OBJECT
public:
left
= new QLabel("Left",
this);
central->addWidget(left);
right
= new QLabel("Right",
this);
central->addWidget(right);
setCentralWidget(central);
QTimer::singleShot(5000,
this,
SLOT(removeRight
()));
QTimer::singleShot(10000,
this,
SLOT(restoreRight
()));
}
public slots:
void removeRight() {
qDebug() << "removeRight";
right->hide();
// right->deleteLater(); // if you do not need the widget any more
}
void restoreRight() {
qDebug() << "restoreRight";
right->show();
}
private:
};
int main(int argc, char *argv[])
{
MainWindow m;
m.show();
return app.exec();
}
#include "main.moc"
#include <QtGui>
#include <QDebug>
class MainWindow: public QMainWindow {
Q_OBJECT
public:
MainWindow(QWidget *p = 0): QMainWindow(p) {
QSplitter *central = new QSplitter(this);
left = new QLabel("Left", this);
central->addWidget(left);
right = new QLabel("Right", this);
central->addWidget(right);
setCentralWidget(central);
QTimer::singleShot(5000, this, SLOT(removeRight()));
QTimer::singleShot(10000, this, SLOT(restoreRight()));
}
public slots:
void removeRight() {
qDebug() << "removeRight";
right->hide();
// right->deleteLater(); // if you do not need the widget any more
}
void restoreRight() {
qDebug() << "restoreRight";
right->show();
}
private:
QLabel *left;
QLabel *right;
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MainWindow m;
m.show();
return app.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
If you really want the splitter to go away entirely then (in this example):
void removeSplitter() {
qDebug() << "removeSplitter";
setCentralWidget(left);
splitter->deleteLater();
right->deleteLater();
}
void removeSplitter() {
qDebug() << "removeSplitter";
setCentralWidget(left);
splitter->deleteLater();
right->deleteLater();
}
To copy to clipboard, switch view to plain text mode
Bookmarks