Results 1 to 5 of 5

Thread: Sizing menubar

  1. #1
    Join Date
    Apr 2013
    Location
    Prague
    Posts
    258
    Thanks
    3
    Thanked 65 Times in 59 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Sizing menubar

    I am trying to create a menubar for a frame window. I can achieve a menubar but with items glued together, something like "FileEditViewHelp" (4 menus, all 4 menus work). Searching for a fix, I have found out that I need to set style sheets for File and other menus, namely set padding. Thus I set

    Qt Code:
    1. padding: 5 px 0px 5px 20px;
    To copy to clipboard, switch view to plain text mode 

    for all menus but I was ignored. (Edit: The "1." was added by the forum, it is not in the stylesheet.)The menus continue being glued together. No padding anywhere. What to do? More precisely, what to do from a Qt Designer? I would like to keep the "GUI look" in the .ui file and not in the code.

    Another question is about menu icons. It seems to be possible to add icons to the menus (I mean texts on the menubar). I created a folder, put icons (.png) into it, created a .qrc and specified icons for the menus (choose resource). The images were found, they were displayed in the resource editor as well as in the Designer data for the menus. But they weren't displayed at application run. I was ignored again. Is it possible to add icons to menus?

    Debian Wheezy, KDE, Qt 4.8.2

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Sizing menubar

    Why not use QMenuBar to build the menu bar and get standard spacing?

    If you want to proceed down the path you are on: the padding is inside the widget, perhaps you wanted the margin.

    Is it possible to add icons to menus?
    Yes, the menu will display the icon associated with the action. Since we cannot see what you have actually done we cannot diagnose the problem.

  3. #3
    Join Date
    Apr 2013
    Location
    Prague
    Posts
    258
    Thanks
    3
    Thanked 65 Times in 59 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Sizing menubar

    I am trying to create the menubar by means of Qt Designer. I am following the standard way "Type here" etc. Naturally, I am creating a QMenuBar. Here is a part of ui_myframe.h resulting from myframe.ui

    Qt Code:
    1. menubar = new QMenuBar(MyFrame);
    2. menubar->setObjectName(QString::fromUtf8("menubar"));
    3. menubar->setGeometry(QRect(0, 0, 800, 25));
    4. QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
    5. sizePolicy.setHorizontalStretch(0);
    6. sizePolicy.setVerticalStretch(0);
    7. sizePolicy.setHeightForWidth(menubar->sizePolicy().hasHeightForWidth());
    8. menubar->setSizePolicy(sizePolicy);
    9. menubar->setMinimumSize(QSize(100, 25));
    10. menuFile = new QMenu(menubar);
    11. menuFile->setObjectName(QString::fromUtf8("menuFile"));
    12. menuFile->setGeometry(QRect(259, 144, 122, 130));
    13. QSizePolicy sizePolicy1(QSizePolicy::Preferred, QSizePolicy::Preferred);
    14. sizePolicy1.setHorizontalStretch(0);
    15. sizePolicy1.setVerticalStretch(0);
    16. sizePolicy1.setHeightForWidth(menuFile->sizePolicy().hasHeightForWidth());
    17. menuFile->setSizePolicy(sizePolicy1);
    18. menuFile->setMinimumSize(QSize(0, 0));
    19. menuFile->setFont(font);
    20. menuFile->setStyleSheet(QString::fromUtf8("padding: 5px 20px 5px 20px"));
    21. QIcon icon;
    22. icon.addFile(QString::fromUtf8(":/icon/rc/file.png"), QSize(), QIcon::Normal, QIcon::Off);
    23. menuFile->setIcon(icon);
    To copy to clipboard, switch view to plain text mode 

    Other menus follow. The result is "FileEditViewHelp", no icons.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Sizing menubar

    Does the Menus Example work correctly for you? The default behaviour of QMenuBar is to neatly space out the QMenu headings. What are you doing that is not standard?

    While you can set an icon on the QMenu objects in Designer the QMenuBar does not render them under Qt 4.8 AFAICT and does a poor job under 5.1 on my Linux box. First things-first though.
    Last edited by ChrisW67; 8th July 2013 at 05:51.

  5. #5
    Join Date
    Apr 2013
    Location
    Prague
    Posts
    258
    Thanks
    3
    Thanked 65 Times in 59 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Sizing menubar

    The culprit seems to be the icon. I have found the following:

    (a) As long as I do not attach the icon, the headings are separated acceptably. I can increase the gaps by blanks before (or after) the heading texts. Not very clean but it works.
    (b) Once I attach an icon, the size of the bounding box of the heading shrinks fo a few pixels (even if it was wider before) and the headings become "FileEditView". The icon is ignored and there seems to be no way to make he bounding box of the heading wider. Trying a long text in the heading does not help: you will see only a few letters in the current minibox.

    Therefore, no icons in menus.

Similar Threads

  1. QScrollArea Sizing
    By LIRiot in forum Newbie
    Replies: 10
    Last Post: 27th October 2010, 13:37
  2. QGraphicsSvgItem sizing
    By jefferai in forum Qt Programming
    Replies: 1
    Last Post: 27th June 2007, 21:48
  3. Sizing problem
    By Levon Nikoghosyan in forum Qt Programming
    Replies: 7
    Last Post: 2nd April 2007, 17:31
  4. sizing question
    By jlgerber in forum Newbie
    Replies: 1
    Last Post: 20th November 2006, 16:48
  5. Sizing Issues
    By Solarity in forum Newbie
    Replies: 7
    Last Post: 13th February 2006, 19:17

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.