码迷,mamicode.com
首页 > 其他好文 > 详细

笔记:QT的菜单

时间:2016-03-20 23:55:54      阅读:237      评论:0      收藏:0      [点我收藏+]

标签:

1.创建菜单栏和菜单

1 QMenuBar *menuBar = new QMenuBar(this);
2 QMenu *file = menuBar->addMenu("&file");//用&来指定快捷键
3 file->addAction("新建");

2.创建可选择的菜单

1 QAction *newFile = file->addAction("打开(&O)");
2 newFile->setCheckable(true);

3.创建带图标的菜单

1 file->addAction(QIcon(":/file/image/new.png"), "关闭");

4.信号槽

1 QAction *print = file->addAction("打印");
2 connect(print, SIGNAL(triggered()), this, SLOT(onPrintTriggered()));

5.创建一组菜单,在这组菜单中只能有一个被选中

 1 QActionGroup *group = new QActionGroup(this);
 2 QAction *actionTxt = group->addAction("txt文件");
 3 actionTxt->setCheckable(true);
 4 QAction *actionPdf = group->addAction("pdf文件");
 5 actionPdf->setCheckable(true);
 6 QAction *actionExcel = group->addAction("excel文件");
 7 actionExcel->setCheckable(true);
 8 actionExcel->setChecked(true);
 9 file->addSeparator();//分隔栏
10 file->addAction(actionTxt);
11 file->addAction(actionPdf);
12 file->addAction(actionExcel);

6.用new来创建菜单

1 QMenu *edit = new QMenu("编辑(&E)", this);
2 menuBar->addMenu(edit);
3 QAction *selectAll = new QAction("全选", this);
4 edit->addAction(selectAll);

7.在按钮上设置菜单

1 QPushButton *button = new QPushButton(this);
2 button->setText("菜单");
3 button->move(50, 50);
4 button->setMenu(file);

 

笔记:QT的菜单

标签:

原文地址:http://www.cnblogs.com/love-me-love-my-code/p/5300057.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!