0
问题:如果我将应用程序的工具栏拉离窗口框架并将其浮动,我无法再对接它。我的窗口层次结构相当复杂,所以我不确定哪一部分我不得不用棍子戳到它的行为。Qt工具栏不会重新编译
我的Qt应用程序使用stackWidget作为它的中心控件。在其中一个包含小部件的堆栈中,我需要一个工具栏和一个图形视图。当我浮动该工具栏时,图形视图展开消耗整个屏幕空间并拒绝缩小以允许工具栏再次停靠。
相关代码如下。我坚持其在自己的项目,看看发生了什么事情,所以减去在头几个额外的定义,这应该编译:
QVBoxLayout* layout0 = new QVBoxLayout(ui->centralWidget);
stack = new QStackedWidget();
layout0->addWidget(stack);
QWidget* screen1 = new QWidget();
QVBoxLayout* layout1 = new QVBoxLayout(screen1);
QToolButton* tool = new QToolButton();
tool->setIcon(QIcon(":/images/sample.bmp"));
tool->setIconSize(QSize(400,400));
QObject::connect(tool,SIGNAL(clicked()),this,SLOT(onPage2()));
layout1->addWidget(tool);
stack->addWidget(screen1);
QWidget* screen2 = new QWidget();
QVBoxLayout* layout2 = new QVBoxLayout(screen2);
QGraphicsView* gview = new QGraphicsView();
layout2->addWidget(gview);
stack->addWidget(screen2);
QToolBar* toolbar = new QToolBar();
toolbar->addAction("home",this,SLOT(onPage1()));
this->addToolBar(Qt::TopToolBarArea,toolbar);
在键入这个过程中,我发现设置工具按钮的最小尺寸似乎可以解决问题。 – AndrewS 2012-02-06 19:31:51