QAction with sub-menu displays a weird arrow image



  • Hello, I create a QAction by getting 'menuAction()' from a QMenu.
    Then, I insert that QAction into a QToolBar of a QMainWindow.
    When displayed, it looks strange... the arrow looks as if only half of it could be shown.

    I looked for a solution or a work-around in the Web, but could not find anything about that.
    I am using Qt 4.5.3.
    Does someone has any idea what is the cause of this phenomenon?

    Thanks in advance,
    Raphy.


  • Qt Champions 2016

    HI and welcome
    Have you tried setting some text also?
    Sounds like a size issue.
    Maybe a picture would help.



  • Hi, thank you for your prompt response.
    There is no text, just icon.
    The cause of size issue did cross my mind, but I cannot change the size of
    a QAction, since it does not inherit QWidget.
    I tried using a QToolButton and add it to the toolbar as a Widget, but when trying to resize, the entire item resized, but the arrow section stayed unchanged.

    I would like to attach a picture, but... I'm new to this forum and couldn't find how to...


  • Qt Champions 2016

    Hi,
    there is no upload picture here, so u need to use other site, like postimage.org or
    anyone you like.
    Could the arrow be the one indicating for sub items?, like in right side?



  • Exactly, that's the arrow.
    I'll upload to some site and add the link right away.

    Here's the link:
    http://s12.postimg.org/c32ytn1cp/qaction.png


  • Qt Champions 2016

    @Raphy
    It does seem strange.
    You do this in Designer or via code?
    If code, we we see it ?



  • @mrjj
    I do this via code, I use 4.6.0 QtDesigner and I am not aware of any way to do it there.
    If it is possible to do in the designer, I'll be happy to know.
    Any way, the code is (more or less):

    ...
    QAction *myAction = aQMenuDefinedInDesigner->menuAction();
    myAction ->setObjectName(QString::fromUtf8("actionName"));
    myAction ->setIcon(someIcon);
    myAction ->setToolTip(SomeTooltip);

    mytoolBar->insertAction(<some Action>, myAction);
    

    All of this is executed during object construction, but I also tried it only after the window displayed, and it didn't make any change.


  • Qt Champions 2016

    @Raphy
    Hi, im not sure the action editor was in Qt 4.6. Think not.
    Is aQMenuDefinedInDesigner a top level menu?


  • Moderators

    seems like a QStyle bug, if you aren't doing anything special other than creating a action.

    What does the following return?

    QApplication::style()->metaObject()->className()
    

    i also assume you dont have a stylesheet set? (On any widget)



  • @mrjj
    No, that menu is a sub-menu of a menu item in the main menu bar of the window.
    However, it is a QMenu.



  • @raven-worx
    Hi,
    Tried it, it returns "QWindowsVistaStyle", since my system is Windows7.
    And you are right assuming I don't use an application based StyleSheet, but I do use style sheets for specific widgets, but not in this case.


  • Moderators

    @Raphy said:

    And you are right assuming I don't use an application based StyleSheet, but I do use style sheets for specific widgets, but not in this case.

    on any widget in the parent hierarchy?
    If so please show the stylesheet code.



  • @raven-worx
    None. Just re-checked to make sure.

    Any way, I looked into maybe a work-around using styleSheet, but no success.
    Do you have any idea in this direction?


  • Moderators

    ok, i just tested a simple toolbar with a toolbutton (with submenu, only an icon and an empty text)
    Using Qt 4.5.3 on Windows 7.

    Everything looks like expected.

    So i would say the error is very likely somewhere in your code.



  • @raven-worx
    OK, thank you for the effort, I appreciate it.
    I prefer that situation since it gives some hope, rather than knowing there's a bug in Qt StyleSheet (or any other part of it).
    If you had to guess, what do you think could make this happen?
    Could you show me your code? maybe I'll see something I'm missing...


  • Moderators

    @Raphy said:

    If you had to guess, what do you think could make this happen?

    maybe you've set some maximum width. Or you do have set some stylesheet which gets derived to the toolbutton.

    Could you show me your code? maybe I'll see something I'm missing...

    Actually pretty simple. But try it and check if this one works. Also try it independently from your existing toolbar.

    QMainWindow* mainWindow = new QMainWindow;
    
    QToolBar* toolbar = mainWindow->addToolBar("Toolbar");
    
    QMenu* menu = new QMenu;
        menu->addAction("Item 1");
        menu->addAction("Item 2");
        menu->addAction("Item 3");
    
    QAction *myAction = toolbar->addAction("");
    myAction->setObjectName(QString::fromUtf8("actionName"));
    myAction->setIcon( QIcon("...") );
    myAction->setToolTip("SomeTooltip");
    myAction->setMenu( menu );
    toolbar->addAction( myAction );
    
    mainWindow->setCentralWidget(new QWidget);
    mainWindow->show();
    


  • @raven-worx
    Thank you!
    I'll try to make it as similar to your code and if it works for me, I'll let you know.

    Could it be that calling 'addAction()' and adding it to the end of the toolbar works while
    I call 'insertAction()' and something there does not work properly?

    Thanks again.


  • Moderators

    @Raphy said:

    Could it be that calling 'addAction()' and adding it to the end of the toolbar works while
    I call 'insertAction()' and something there does not work properly?

    addAction() is just a call to insertAction() with index 0
    So no ;)



  • With all the good advice and help, I still cannot get it right.
    Here's what I get: http://s12.postimg.org/c32ytn1cp/qaction.png

    Any other ideas, anyone?



  • @raven-worx said:

    ok, i just tested a simple toolbar with a toolbutton (with submenu, only an icon and an empty text)
    Using Qt 4.5.3 on Windows 7.

    Everything looks like expected.

    Hi again,
    I just realized I (innocently) misinformed you, it turns out I use Qt 4.5.1, not .3. Sorry.
    If it's possible to try it with this version, I would be grateful.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.