Did anyone face a problem of putting buttons (or any other widgets) on the top of a splitter handle? I've tried to get the handle, set its layout and put the controls there, but I got some weird look.
My main goal is to create a selector dialog as depicted below:
What I get:
Code:
QDialog dialog = new QDialog();
dialog.setLayout(new QVBoxLayout());
QSplitter splitter = new QSplitter();
splitter.setSizePolicy(new QSizePolicy(QSizePolicy.Policy.MinimumExpanding, QSizePolicy.Policy.Fixed));
splitter.addWidget(new QListWidget());
splitter.addWidget(new QTableWidget());
dialog.layout().addWidget(splitter);
QSplitterHandle h = splitter.handle(1);
h.setFixedWidth(30); // I added this line to show the splitter handle
QVBoxLayout lt = new QVBoxLayout();
lt.setSpacing(0);
lt.setMargin(0);
lt.addWidget(new QPushButton("Hello", dialog));
lt.addWidget(new QPushButton("Good bye", dialog));
h.setLayout(lt);
dialog.show();
This gives better result:
For better result I'd suggest to subclass QSplitterHandle and reimplement
sizeHint()
. Look through QSplitterHandle documentation.You can change layout setting to get exact button positions. For example:
To remove "relief"-bar you must subclass from QSplitterHandle and reimplement
paintEvent()
.