是否有人遇到将按钮(或任何其他小部件)放在分离器手柄顶部的问题?我试图拿到手柄,设置它的布局并将控件放在那里,但我得到了一些奇怪的外观。
我的主要目标是创建一个选择器对话框,如下所示:
我得到什么:
代码:
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();