Qt switch disconnected

I want the user to be able to disable QSplitter at runtime. The call setEnabled(false)does this, but also disables all child widgets - which I don't want. Is there any way to achieve this? Should I turn off the splitter and then manually turn on all the child widgets? This seems rather cumbersome, for something that should be reasonably common practice.

Can anyone suggest something?

+5
source share
3 answers

In fact, I never saw anyone turn off the splitter. They are there, so the user can compose the user interface at their discretion, so why would anyone disable it? Either you need a splitter, or you can use one of the usual layouts (which the user cannot resize).

If you still want to try, I think you should take a look at closeestLegalPosition () or getRange () . If you just return the width of the widget, resizing should stop.

+1
source

Do it:

for (int i = 0; i < splitter->count(); i++)
{
    QSplitterHandle *hndl = splitter->handle(i);
    hndl->setEnabled(false);
}
+10
source

. ( ) FixedSize Qt::ArrowCursor. ( ), - 1.

( main.cpp):

#include <QtGui>

 int main(int argc, char *argv[])
 {
     QApplication app(argc, argv);
     QWidget window;
     window.resize(800, 300);
     window.setWindowTitle("Splitter Test");
     window.show();

     QSplitter *splitter = new QSplitter(&window);
     QListView *listview = new QListView;
     QTreeView *treeview = new QTreeView;
     QTextEdit *textedit = new QTextEdit;

     splitter->addWidget(listview);
     splitter->addWidget(treeview);
     splitter->addWidget(textedit);
     splitter->setChildrenCollapsible(false);

     splitter->show();
     listview->show();
     treeview->show();
     textedit->show();

     //make the lisview 'fix'
     listview->setFixedSize(listview->width(), listview->height());
     //change the cursor over the splitter handle between listview and
     //treeview to ArrowCursor
     splitter->handle(1)->setCursor(Qt::ArrowCursor);;

     return app.exec();
 }

Now the first separator descriptor disabled, and the second one works.

0
source

All Articles