QMenu* ratio_menu = new QMenu(tr("Ratio"));ratio_menu->addAction("4:3",this,SLOT(setRatio_4_3()));ratio_menu->addAction("16:9",this,SLOT(setRatio_16_9()));ratio_menu->addAction("16:10",this,SLOT(setRatio_16_10()));ratio_menu->addAction(tr("Default"),
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/29 00:21:41
QMenu* ratio_menu = new QMenu(tr("Ratio"));ratio_menu->addAction("4:3",this,SLOT(setRatio_4_3()));ratio_menu->addAction("16:9",this,SLOT(setRatio_16_9()));ratio_menu->addAction("16:10",this,SLOT(setRatio_16_10()));ratio_menu->addAction(tr("Default"),
QMenu* ratio_menu = new QMenu(tr("Ratio"));
ratio_menu->addAction("4:3",this,SLOT(setRatio_4_3()));
ratio_menu->addAction("16:9",this,SLOT(setRatio_16_9()));
ratio_menu->addAction("16:10",this,SLOT(setRatio_16_10()));
ratio_menu->addAction(tr("Default"),this,SLOT(setRatio_0()));
menu = new QMenu(this);
menu->addMenu(ratio_menu);
setContextMenuPolicy(Qt::CustomContextMenu);
connect(this,SIGNAL(customContextMenuRequested(const QPoint&)),
this,SLOT(showMenu(const QPoint&)));
代码的详解
QMenu* ratio_menu = new QMenu(tr("Ratio"));ratio_menu->addAction("4:3",this,SLOT(setRatio_4_3()));ratio_menu->addAction("16:9",this,SLOT(setRatio_16_9()));ratio_menu->addAction("16:10",this,SLOT(setRatio_16_10()));ratio_menu->addAction(tr("Default"),
创建一个菜单,ratio_menu.里面有各个比例的选项(Action)(4:3 16:9什么的),每个Action对应一个slot,即槽函数.
创建一个菜单menu作为ratio_menu的父菜单,当有上下文菜单请求信号发出的时候,调用showMenu槽函数.
大概就是鼠标右键,出现比例设置菜单,用户点其中一个,调用对应的slot,槽函数.