Results 1 to 2 of 2

Thread: QMenuBar minimum size

  1. #1
    Join Date
    Jan 2007
    Location
    Rome
    Posts
    30
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default QMenuBar minimum size

    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

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QMenuBar minimum size

    Does this do what you want?
    Qt Code:
    1. class MenuBar : public QMenuBar
    2. {
    3. public:
    4. MenuBar(QWidget* parent = 0)
    5. : QMenuBar(parent) { }
    6.  
    7. QSize sizeHint() const
    8. {
    9. int ext = style()->pixelMetric(QStyle::PM_ToolBarExtensionExtent);
    10. return QMenuBar::sizeHint() + QSize(ext, 0);
    11. }
    12. };
    13.  
    14. MenuBar* menuBar = new MenuBar(toolBar);
    15. menuBar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); // <-- !
    16. menuBar->addMenu(...);
    17. ...
    18. toolBar->addWidget(menuBar);
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

Similar Threads

  1. Replies: 1
    Last Post: 24th October 2006, 16:40
  2. Qt 4.1.1 linker warnings
    By Matt Smith in forum Installation and Deployment
    Replies: 0
    Last Post: 26th February 2006, 22:14
  3. QMenuBar size policy
    By krivenok in forum Qt Programming
    Replies: 3
    Last Post: 16th January 2006, 15:13

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.