Important: Please read the Qt Code of Conduct -

QToolBar initial size is strange

  • This code:

        QToolBar t(&w);
        QIcon dragRect("C:/Users/amonra/Documents/GitHub/DSS/DeepSkyStacker/Buttons/ButtonSelect_Up.bmp");
        t.addAction(dragRect, "", &editor, "dragButtonPressed");
        //t.setFixedSize(50, 50);
        t.setIconSize(QSize(48, 48));

    creates the toolbar with a very strange size (100 wide, 30 high) as reported by this code:

        if (m_pToolBar)
            qreal width(m_pToolBar->width());
            qreal height(m_pToolBar->height());
            QPoint point(sz.width() - width, sz.height() - height);
            qDebug() << "width" << width << "height" << height;

    in the widget's resizeEvent(code) on the first invocation. The result is that the ToolBar is incorrectly positioned within the widget.

    If I then resize the widget the ToolBar size is reported as a much more sane value of 59 wide 58 high (is height off by 1?) and it is then positioned correctly

  • Bumpety bump

  • Lifetime Qt Champion


    Please show some patience and wait at least 24 hours before bumping your own thread. This is a voluntary driven forum and people might not live in the same time zone as you.

    Which version of Qt ?
    On which OS ?
    If Linux, what distribution ? Desktop environment ?

Log in to reply