Pregunta

I use the Qt Designer to design .ui files and compile them in my VS-Project. We have a Toolbar class, derived from QToolbar.

Class initialization looks like this.

MyToolBar::ToolBar(QWidget* qWidgetParent) :
    ToolBar(qWidgetParent),
    mUiToolBar(new Ui::MyToolBar())
    {
        mUiToolBar->setupUi(this);
        //...
     }

Everything works fine for fixed positions and sizes. But if I start using a layout for automatic formating everything is broken. In this case everything is on the topleft position.

Any Idea whats happen in this case? What is the correct way to use layouts in a QToolbar?

edit: i have copied the code from my project. In this MyToolBar is derived by ToolBar, a class for managing the same functionality. ToolBar is derived by QToolBar.

¿Fue útil?

Solución

I don't think a ToolBar is meant to have a Layout. What are you trying to achieve with that?

Seeing everything in the topleft position that should be in a Layout is a sign that either those child Widgets were not added to the Layout (using QLayout::addWidget(...)) or that the Layout was not added to the parent Widget (your ToolBar, using QWidget::setLayout(...)).

Also, you probably meant to call QToolBar(qWidgetParent), in stead of ToolBar(qWidgetParent),.

Otros consejos

You are forgetting to call QToolBar::addWidget(), but you are setting parent of the widgets to the QToolBar widget.

This will create all widgets at (0,0) position (relative to the parent), but it will not layout them as you are expecting to.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top