I have a QT main window and on top of this I want to add a widget ( containing buttons), as similar to image below. If I add a dock widget , it is added in separate row, but not added as overlay on existing main window. Any inputs ?
问问题
668 次
2 回答
0
您应该考虑使用 QStackedLayout 来做到这一点。
于 2014-01-18T17:03:59.747 回答
0
最简单的方法是将覆盖小部件的父级设置为主窗口。但是因为它不会出现在任何布局中,所以您必须自己处理它的几何形状。如果您想要多个叠加层,最后添加的将是最顶部的。
#include <QApplication>
#include <QtGui>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QMainWindow *window = new QMainWindow();
QWidget *centralWiddget = new QWidget();
window->setCentralWidget(centralWiddget);
QVBoxLayout *layout = new QVBoxLayout(centralWiddget);
QPushButton *button = new QPushButton("Button in a layout");
layout->addWidget(button);
QPushButton *overlayButton = new QPushButton("Button overlay");
overlayButton->setParent(window);
overlayButton->setGeometry(40, 40, 120, 30)
window->show();
return app.exec();
}
于 2013-10-18T00:11:11.037 回答