使用Qt框架中的QGraphicsScene,您需要按照以下步骤进行操作:
QGraphicsScene scene;
QGraphicsView view(&scene);
QGraphicsItem *item = new QGraphicsRectItem(0, 0, 100, 100); // 创建一个矩形图形项
scene.addItem(item); // 将图形项添加到场景中
scene.setBackgroundBrush(Qt::gray);
void MyScene::mousePressEvent(QGraphicsSceneMouseEvent *event) {
// 处理鼠标点击事件
}
QMainWindow window;
window.setCentralWidget(&view);
window.show();
以上是使用QGraphicsScene的基本步骤,您可以根据实际需求进行更多的操作和定制。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:Qt图形视图框架:QGraphicsScene详解