, ( ), , Label, QLabel .
( ) :
class Label : public QLabel
{
public:
Label(QWidget* pParent=0, Qt::WindowFlags f=0) : QLabel(pParent, f) {};
Label(const QString& text, QWidget* pParent = 0, Qt::WindowFlags f = 0) : QLabel(text, pParent, f){};
protected :
virtual void mouseReleaseEvent ( QMouseEvent * ev ) {
QMenu MyMenu(this);
MyMenu.addActions(this->actions());
MyMenu.exec(ev->globalPos());
}
};
Label , .
, MainFrm (Label). :
MainFrm::MainFrm(QWidget *parent) : MainFrm(parent), ui(new Ui::MainFrm)
{
ui->setupUi(this);
QAction* pAction1 = new QAction("foo", ui->label);
QAction* pAction2 = new QAction("bar", ui->label);
QAction* pAction3 = new QAction("test", ui->label);
ui->label->addAction(pAction1);
ui->label->addAction(pAction2);
ui->label->addAction(pAction3);
connect(pAction1, SIGNAL(triggered()), this, SLOT(onAction1()));
connect(pAction2, SIGNAL(triggered()), this, SLOT(onAction2()));
connect(pAction3, SIGNAL(triggered()), this, SLOT(onAction3()));
}