PDA

View Full Version : Selection of actions in QActionGroup not visible



pospiech
25th August 2009, 21:09
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?



#ifndef QPLOT3DMENU_H_
#define QPLOT3DMENU_H_

class QActionGroup;
class QAction;
#include <QtGui/QMenu>

class QPlot3DMenu : public QMenu
{
Q_OBJECT
public:
QPlot3DMenu(QWidget* parent = 0);
virtual ~QPlot3DMenu();

private:
QMenu *menuCoordinate_style;

QAction *actionBox;
QAction *actionFrame;
QAction *actionNone;

QActionGroup *alignmentGroupCoordinateStyle;

private:
void setupUi(QWidget* parent);
void retranslateUi(QWidget *widget);
};
#endif




#include "QPlot3DMenu.h"

#include <QtGui/QActionGroup>
#include <QtGui/QAction>
#include <QtGui/QMenu>

QPlot3DMenu::QPlot3DMenu( QWidget* parent /*= 0*/) : QMenu(parent)
{
setupUi(this);
}


QPlot3DMenu::~QPlot3DMenu()
{
}


void QPlot3DMenu::setupUi(QWidget* parent)
{

// --- Coordinate Style -------------------------------------------------------
menuCoordinate_style = new QMenu(this);
menuCoordinate_style->setObjectName(QString::fromUtf8("menuCoordinate_style"));

actionBox = new QAction(parent);
actionBox->setObjectName(QString::fromUtf8("actionBox"));
QIcon icon6;
icon6.addFile(QString::fromUtf8(":/box.png"), QSize(), QIcon::Normal, QIcon::Off);
actionBox->setIcon(icon6);

actionFrame = new QAction(parent);
actionFrame->setObjectName(QString::fromUtf8("actionFrame"));
QIcon icon7;
icon7.addFile(QString::fromUtf8(":/frame.png"), QSize(), QIcon::Normal, QIcon::Off);
actionFrame->setIcon(icon7);

actionNone = new QAction(parent);
actionNone->setObjectName(QString::fromUtf8("actionNone"));
QIcon icon8;
icon8.addFile(QString::fromUtf8(":/grid.png"), QSize(), QIcon::Normal, QIcon::Off);
actionNone->setIcon(icon8);

alignmentGroupCoordinateStyle = new QActionGroup(parent);
alignmentGroupCoordinateStyle->addAction(actionBox);
alignmentGroupCoordinateStyle->addAction(actionFrame);
alignmentGroupCoordinateStyle->addAction(actionNone);
actionBox->setChecked(true);

menuCoordinate_style->addAction(actionBox);
menuCoordinate_style->addAction(actionFrame);
menuCoordinate_style->addAction(actionNone);

parent->addAction(menuCoordinate_style->menuAction());

retranslateUi(parent);

QMetaObject::connectSlotsByName(parent);
} // setupUi



void QPlot3DMenu::retranslateUi(QWidget *widget)
{
actionBox->setText(QApplication::translate("MainWindow", "box", 0, QApplication::UnicodeUTF8));
actionFrame->setText(QApplication::translate("MainWindow", "frame", 0, QApplication::UnicodeUTF8));
actionNone->setText(QApplication::translate("MainWindow", "none", 0, QApplication::UnicodeUTF8));

menuCoordinate_style->setTitle(QApplication::translate("MainWindow", "coordinate style", 0, QApplication::UnicodeUTF8));

} // retranslateUi



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

nish
26th August 2009, 02:22
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?

pospiech
26th August 2009, 07:54
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

nish
26th August 2009, 09:17
sorry i missed the addAction line of menu !

pospiech
27th August 2009, 22:18
I have no seen that I have to make the actions selectable, then it works.