Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QAction with sub-menu displays a weird arrow image

QAction with sub-menu displays a weird arrow image

Scheduled Pinned Locked Moved Unsolved General and Desktop
20 Posts 3 Posters 6.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Raphy
    wrote on last edited by Raphy
    #1

    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.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

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

      R 1 Reply Last reply
      0
      • mrjjM mrjj

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

        R Offline
        R Offline
        Raphy
        wrote on last edited by
        #3

        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...

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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?

          R 1 Reply Last reply
          0
          • mrjjM mrjj

            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?

            R Offline
            R Offline
            Raphy
            wrote on last edited by
            #5

            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

            mrjjM 1 Reply Last reply
            0
            • R Raphy

              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

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

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

              R 1 Reply Last reply
              0
              • mrjjM mrjj

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

                R Offline
                R Offline
                Raphy
                wrote on last edited by
                #7

                @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.

                mrjjM 1 Reply Last reply
                0
                • R Raphy

                  @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.

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

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

                  R 1 Reply Last reply
                  0
                  • raven-worxR Offline
                    raven-worxR Offline
                    raven-worx
                    Moderators
                    wrote on last edited by raven-worx
                    #9

                    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)

                    --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                    If you have a question please use the forum so others can benefit from the solution in the future

                    R 1 Reply Last reply
                    0
                    • mrjjM mrjj

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

                      R Offline
                      R Offline
                      Raphy
                      wrote on last edited by
                      #10

                      @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.

                      1 Reply Last reply
                      0
                      • raven-worxR raven-worx

                        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)

                        R Offline
                        R Offline
                        Raphy
                        wrote on last edited by
                        #11

                        @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.

                        raven-worxR 1 Reply Last reply
                        0
                        • R Raphy

                          @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.

                          raven-worxR Offline
                          raven-worxR Offline
                          raven-worx
                          Moderators
                          wrote on last edited by
                          #12

                          @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.

                          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                          If you have a question please use the forum so others can benefit from the solution in the future

                          R 1 Reply Last reply
                          0
                          • raven-worxR raven-worx

                            @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.

                            R Offline
                            R Offline
                            Raphy
                            wrote on last edited by
                            #13

                            @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?

                            1 Reply Last reply
                            0
                            • raven-worxR Offline
                              raven-worxR Offline
                              raven-worx
                              Moderators
                              wrote on last edited by raven-worx
                              #14

                              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.

                              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                              If you have a question please use the forum so others can benefit from the solution in the future

                              R 2 Replies Last reply
                              0
                              • raven-worxR raven-worx

                                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.

                                R Offline
                                R Offline
                                Raphy
                                wrote on last edited by
                                #15

                                @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...

                                raven-worxR 1 Reply Last reply
                                0
                                • R Raphy

                                  @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...

                                  raven-worxR Offline
                                  raven-worxR Offline
                                  raven-worx
                                  Moderators
                                  wrote on last edited by raven-worx
                                  #16

                                  @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();
                                  

                                  --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                                  If you have a question please use the forum so others can benefit from the solution in the future

                                  R 1 Reply Last reply
                                  0
                                  • raven-worxR raven-worx

                                    @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();
                                    
                                    R Offline
                                    R Offline
                                    Raphy
                                    wrote on last edited by
                                    #17

                                    @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.

                                    raven-worxR 1 Reply Last reply
                                    0
                                    • R Raphy

                                      @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.

                                      raven-worxR Offline
                                      raven-worxR Offline
                                      raven-worx
                                      Moderators
                                      wrote on last edited by
                                      #18

                                      @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 ;)

                                      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                                      If you have a question please use the forum so others can benefit from the solution in the future

                                      R 1 Reply Last reply
                                      0
                                      • raven-worxR raven-worx

                                        @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 ;)

                                        R Offline
                                        R Offline
                                        Raphy
                                        wrote on last edited by
                                        #19

                                        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?

                                        1 Reply Last reply
                                        0
                                        • raven-worxR raven-worx

                                          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.

                                          R Offline
                                          R Offline
                                          Raphy
                                          wrote on last edited by
                                          #20

                                          @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.

                                          1 Reply Last reply
                                          0

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved