转自:http://blog.csdn.net/howdyhappy/article/details/5741313
Actions 可以被添加进菜单栏和工具条,并且自动保持同步。例如,在文字处理程序中,单击工具条上的“粗体”按扭,则相应的菜单项“粗体”也会被自动选中。
QAction 作为菜单项可以为其单独设置字体,用setFont() 函数。
setIcon(), setText(), setIconText(), setShortcut(), setStatusTip(), setWhatsThis() 和setToolTip()
添加Actions:QWidget::addAction() QGraphicsWidget::addAction()
QAction 一旦创建应加入菜单栏和工具条,然后将其triggered() 连接到slot
openAct = new QAction(QIcon(":/images/open.png"), tr("&Open..."), this);
openAct->setShortcuts(QKeySequence::Open);
openAct->setStatusTip(tr("Open an existing file"));
connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
fileMenu->addAction(openAct);
fileToolBar->addAction(openAct);
推荐创建QAction 时将使用它的窗体作为其parent。通常QAction 是应用程序主窗体的children。