Advertisement

Qt修炼手册图形:用户自定义QGraphicsItem

阅读量:

1.前言

Qt框架中内置的Item组件可能无法完全契合实际需求,因此有必要开发专属的QGraphicsItem对象。类似于QPushButton的功能设计,当鼠标事件被触发时,为实现点击按钮后图像的切换效果,可通过重写paint方法来构建个性化的QGraphicsItem组件。

2.一个简单的实验

复制代码
>       1. #include <QtWidgets/QApplication>

>  
>       2. #include "MyItem.h"
>  
>       3. #include <qgraphicsscene.h>
>  
>       4. #include <qgraphicsview.h>
>  
>       5.  
>  
>       6. #define WIDTH 300
>  
>       7. #define HEIGHT 200
>  
>       8.  
>  
>       9. int main(int argc, char *argv[])
>  
>       10. {
>  
>       11.     QApplication a(argc, argv);
>  
>       12.     QGraphicsScene 

全部评论 (0)

还没有任何评论哟~