面向对象菜单系统
OOP menu system
我正在尝试使用Qt4.8中的QGraphics制作菜单系统(带子菜单)。复合模式听起来是一个很好的解决方案,但是我被卡住了。
这是UML图:https://i.stack.imgur.com/JgWpQ.png
对象的结构像树。
+-------------+
|Root |+---------------------+
+-------------+| |
+ | |
| | |
| | |
| v v
+-------<++ +----------+ +----------------+
|Leaf1 | +---+|MenuNode1 | | MenuNode2 |+--------+
+---------+ | +----------+ +----------------+ |
| + + |
| | | |
v v v v
+---------+ +-----------+ +-------------+ +-------------+
|Leaf2 | |Leaf3 | | MenuNode4 | |Leaf5 |
+---------+ +-----------+ +-------+-----+ +-------------+
+ |
| |
| v
+---------+ | +------------+
| <-+ | |
+---------+ +------------+
第一个问题是Qt绘制了孔结构,但我只想显示当前节点的子节点。因此,我试图通过使所有AbstractMenuItems不可见和
来解决这个问题void MenuNode::paint( QPainter *painter, ....) {
if( this->parentWidget() == AbstractMenuItem::currentPosition) { //show only the direct children
for(int i = 0; i<3; i++) {//show only 3 elements at a time
child->at(i)->setVisibile(true);
child->at(i)->setFocus( i == 1 );
}
} else { //paint as a child
painter->drawText("Child MenuNode");
}
}
我认为我的想法不是太离谱。有什么建议可以让它变得更好吗?
首先,我假定您不希望您的菜单项是Qt小部件。
接下来,为了封装图形对象,您可以使用QGraphicsScene作为可编程的"字段",并将QGraphicsItem用于您想要编程的所有菜单项。但是,需要更多的问题/答案来指定更详细的实现。我相信这些类在Qt 4.8中也是可用的。您还可以轻松地获得基于opengl的编程的优势。
相关文章:
- C++,系统无法执行指定的程序
- 在UNIX系统中使用DIR查找文件的字节大小
- 无法获取菜单选择以运行函数.C++
- 如何在OpenGL菜单系统中实现文本的智能渲染
- 将WM_CHANGEUISTATE发送到窗口应用程序后,当用鼠标访问菜单时,助记符不会显示在系统菜单上
- 当我最大化子窗口时,系统菜单消失
- 如何将系统图标放在菜单中
- 系统托盘上下文菜单空白
- 使用本机C 包装器作为NCurses,如何创建菜单/子菜单系统
- TrackPopupMenu 显示的系统菜单与窗口状态不匹配
- 更换Windows上的系统菜单弹出窗口
- 右键单击系统托盘图标,然后单击C 中的上下文菜单
- 如何在Qt中获取文件系统操作的上下文菜单
- 对系统菜单进行子类划分
- OOP游戏菜单系统开发概念
- Delphi XE-无法从系统菜单中删除项目
- MFC正在将项添加到系统菜单
- C++菜单类系统结构:渲染顺序,变量类函数
- 为菜单系统实现lua回调
- 面向对象菜单系统