Results 1 to 5 of 5

Thread: Selection of actions in QActionGroup not visible

  1. #1
    Join Date
    Feb 2008
    Posts
    157
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Selection of actions in QActionGroup not visible

    I am trying to implement a popupmenu, but seam to fail somehow. (If this is considered as a newbie question move it there)

    I placed the menu in a new class. I have mainly groups where a single action out of a group shall be selected. But I see neither a selection nor can I select anything. So what am I doing wrong?

    Qt Code:
    1. #ifndef QPLOT3DMENU_H_
    2. #define QPLOT3DMENU_H_
    3.  
    4. class QAction;
    5. #include <QtGui/QMenu>
    6.  
    7. class QPlot3DMenu : public QMenu
    8. {
    9. Q_OBJECT
    10. public:
    11. QPlot3DMenu(QWidget* parent = 0);
    12. virtual ~QPlot3DMenu();
    13.  
    14. private:
    15. QMenu *menuCoordinate_style;
    16.  
    17. QAction *actionBox;
    18. QAction *actionFrame;
    19. QAction *actionNone;
    20.  
    21. QActionGroup *alignmentGroupCoordinateStyle;
    22.  
    23. private:
    24. void setupUi(QWidget* parent);
    25. void retranslateUi(QWidget *widget);
    26. };
    27. #endif
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "QPlot3DMenu.h"
    2.  
    3. #include <QtGui/QActionGroup>
    4. #include <QtGui/QAction>
    5. #include <QtGui/QMenu>
    6.  
    7. QPlot3DMenu::QPlot3DMenu( QWidget* parent /*= 0*/) : QMenu(parent)
    8. {
    9. setupUi(this);
    10. }
    11.  
    12.  
    13. QPlot3DMenu::~QPlot3DMenu()
    14. {
    15. }
    16.  
    17.  
    18. void QPlot3DMenu::setupUi(QWidget* parent)
    19. {
    20.  
    21. // --- Coordinate Style -------------------------------------------------------
    22. menuCoordinate_style = new QMenu(this);
    23. menuCoordinate_style->setObjectName(QString::fromUtf8("menuCoordinate_style"));
    24.  
    25. actionBox = new QAction(parent);
    26. actionBox->setObjectName(QString::fromUtf8("actionBox"));
    27. QIcon icon6;
    28. icon6.addFile(QString::fromUtf8(":/box.png"), QSize(), QIcon::Normal, QIcon::Off);
    29. actionBox->setIcon(icon6);
    30.  
    31. actionFrame = new QAction(parent);
    32. actionFrame->setObjectName(QString::fromUtf8("actionFrame"));
    33. QIcon icon7;
    34. icon7.addFile(QString::fromUtf8(":/frame.png"), QSize(), QIcon::Normal, QIcon::Off);
    35. actionFrame->setIcon(icon7);
    36.  
    37. actionNone = new QAction(parent);
    38. actionNone->setObjectName(QString::fromUtf8("actionNone"));
    39. QIcon icon8;
    40. icon8.addFile(QString::fromUtf8(":/grid.png"), QSize(), QIcon::Normal, QIcon::Off);
    41. actionNone->setIcon(icon8);
    42.  
    43. alignmentGroupCoordinateStyle = new QActionGroup(parent);
    44. alignmentGroupCoordinateStyle->addAction(actionBox);
    45. alignmentGroupCoordinateStyle->addAction(actionFrame);
    46. alignmentGroupCoordinateStyle->addAction(actionNone);
    47. actionBox->setChecked(true);
    48.  
    49. menuCoordinate_style->addAction(actionBox);
    50. menuCoordinate_style->addAction(actionFrame);
    51. menuCoordinate_style->addAction(actionNone);
    52.  
    53. parent->addAction(menuCoordinate_style->menuAction());
    54.  
    55. retranslateUi(parent);
    56.  
    57. QMetaObject::connectSlotsByName(parent);
    58. } // setupUi
    59.  
    60.  
    61.  
    62. void QPlot3DMenu::retranslateUi(QWidget *widget)
    63. {
    64. actionBox->setText(QApplication::translate("MainWindow", "box", 0, QApplication::UnicodeUTF8));
    65. actionFrame->setText(QApplication::translate("MainWindow", "frame", 0, QApplication::UnicodeUTF8));
    66. actionNone->setText(QApplication::translate("MainWindow", "none", 0, QApplication::UnicodeUTF8));
    67.  
    68. menuCoordinate_style->setTitle(QApplication::translate("MainWindow", "coordinate style", 0, QApplication::UnicodeUTF8));
    69.  
    70. } // retranslateUi
    To copy to clipboard, switch view to plain text mode 

    The icons are not shown either. However I have never used resources and have no idea how to integrate them into Visual Studio correct.

    Matthias

  2. #2
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: popup menu

    i did not go through your whole code .. but i think your approach is wrong... basically you are inheriting a qmenu and then placing a qmenu again as its child? why? why cant you just add action to the
    QPlot3DMenu class itself?

  3. #3
    Join Date
    Feb 2008
    Posts
    157
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: popup menu

    Quote Originally Posted by MrDeath View Post
    i did not go through your whole code .. but i think your approach is wrong... basically you are inheriting a qmenu and then placing a qmenu again as its child? why? why cant you just add action to the
    QPlot3DMenu class itself?
    The code is not the full example (but the other code is in principle the same). I have many submenus which have actions. And since submenus are supported by Qt, I do not see what is wrong about it.

    But about the constructors. Should it be the parent class (the widget from whichin the popup-menu is constructed), or the 'this', the menu class itsself? Is it correct the way it is now? There the parent of QMenus is the current class, but the parent of the actions is the parent QWidget.

    The principle question is still unsolved. Why do I not see the Actions as a selection group, like shown here: http://doc.trolltech.com/4.5/qactiongroup.html#details

    Matthias

  4. #4
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: popup menu

    sorry i missed the addAction line of menu !

  5. #5
    Join Date
    Feb 2008
    Posts
    157
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: popup menu

    I have no seen that I have to make the actions selectable, then it works.

Similar Threads

  1. Replies: 1
    Last Post: 18th November 2009, 23:21

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
  •  
Qt is a trademark of The Qt Company.