1

how to make make qsplitter unmovable by user and add possibility to enable/disable this function? Thankyou.

Sacha_D
  • 68
  • 1
  • 10
  • 3
    `QSplitter` is inherent `QWidget` so you can use the [enabled flag](http://doc.qt.io/qt-5/qwidget.html#enabled-prop) – Simon Apr 15 '18 at 11:15
  • `your_splitter->setEnabled(false);` – eyllanesc Apr 15 '18 at 11:44
  • No. This disables all children widgets too. I want that it acts like a normal layout. – Sacha_D Apr 15 '18 at 20:05
  • A long shot but... try disabling the various [`QSplitterHandle`s](http://doc.qt.io/qt-5/qsplitter.html#handle) associated with the `QSplitter`. – G.M. Apr 15 '18 at 21:46

1 Answers1

1

Blocking the QSplitter handler can be done using the QSplitterHandler as @G.M. suggested in the comment.

Here is an example code (assuming you'r using QMainWindow)

#include <QCheckBox>
#include <QSplitter>
#include <QLabel>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    QSplitter * poSplitter = new QSplitter(this);
    QLabel * poLbl = new QLabel("Some place holer",this);
    QCheckBox * poToggleSplitter = new QCheckBox("Block splitter", this);

    poSplitter->addWidget(poLbl);
    poSplitter->addWidget(poToggleSplitter);

    connect(poToggleSplitter, &QCheckBox::clicked,
            [poSplitter](bool bChecked)
    {
        // Block splitter movement
        poSplitter->handle(1)->setEnabled(!bChecked);
    });

    this->setCentralWidget(poSplitter);
}
Simon
  • 1,522
  • 2
  • 12
  • 24