PDA

View Full Version : QMenuBar minimum size



Angelo Moriconi
14th June 2007, 08:58
Hi all !
I've added a QMenuBar inside a QToolBar and I want to set its size policy to constrain the menubar to have the necessary size to visualize all the QMenu without truncate any menu.
With the setSizePolicy I can control the horizontal and vertical policy but I don't know how to retrieve the minimum size (to set in the SizeHint method) that visualize all the items.
Any suggestions ?

Thanks,

Angelo

jpn
14th June 2007, 22:14
Does this do what you want?


class MenuBar : public QMenuBar
{
public:
MenuBar(QWidget* parent = 0)
: QMenuBar(parent) { }

QSize sizeHint() const
{
int ext = style()->pixelMetric(QStyle::PM_ToolBarExtensionExtent);
return QMenuBar::sizeHint() + QSize(ext, 0);
}
};

MenuBar* menuBar = new MenuBar(toolBar);
menuBar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); // <-- !
menuBar->addMenu(...);
...
toolBar->addWidget(menuBar);