Obsolete Members for QGraphicsScene
QGraphicsScene 类的以下成员已被废弃。提供这些成员是为了确保旧源代码能够继续运行。我们强烈建议不要在新代码中使用它们。
受保护函数
(deprecated) virtual void | drawItems(QPainter *painter, int numItems, QGraphicsItem *[] items, const QStyleOptionGraphicsItem[] options, QWidget *widget = nullptr) |
成员函数文档
[virtual protected, deprecated] void QGraphicsScene::drawItems(QPainter *painter, int numItems, QGraphicsItem *[] items, const QStyleOptionGraphicsItem[] options, QWidget *widget = nullptr)
此函数已弃用。我们强烈建议不要在新代码中使用它。
使用提供的painter 绘制给定的items ,该操作发生在背景绘制完成后、前景绘制开始之前。所有绘制均在场景坐标系中进行。在绘制每个项目之前,必须使用QGraphicsItem::sceneTransform()对绘制器进行变换。
options 参数是items 中每个项的样式选项对象列表。numItems 参数表示items 中的项数以及options 中的选项数。widget 参数是可选的;若指定,则应指向待绘制的控件。
默认实现会准备绘制矩阵,并对所有项目调用QGraphicsItem::paint()。重写此函数可为场景中的所有项目提供自定义绘制,从而完全控制每个项目的绘制方式。在某些情况下,这可以显著提高绘制性能。
示例:
void CustomScene::drawItems(QPainter *painter, int numItems,
QGraphicsItem *items[],
const QStyleOptionGraphicsItem options[],
QWidget *widget)
{
for (int i = 0; i < numItems; ++i) {
// Draw the item
painter->save();
painter->setTransform(items[i]->sceneTransform(), true);
items[i]->paint(painter, &options[i], widget);
painter->restore();
}
}自 Qt 4.6 起,除非将QGraphicsView::IndirectPainting 标志作为优化标志指定,否则该函数将不再被调用。
另请参阅 drawBackground() 和drawForeground()。
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.