gpt4 book ai didi

c++ - GraphicsView 上的 Qt QColor 和 QBrush?

转载 作者:行者123 更新时间:2023-11-28 05:55:32 24 4
gpt4 key购买 nike

如何使用 RBG 值为 QBrush 设置自定义颜色?然后在 GraphicsView 上用画笔画一个矩形。

到目前为止我已经尝试过:

QBrush *goldBrush = new QBrush(QColor(212,175,55));
scene->addRect(0,415,20,50,noPen,goldBrush);

错误信息是:

error: C2664: 'QGraphicsRectItem *QGraphicsScene::addRect(qreal,qreal,qreal,qreal,const QPen &,const QBrush &)' : cannot convert argument 6 from 'QBrush *' to 'const QBrush &' Reason: cannot convert from 'QBrush *' to 'const QBrush' No constructor could take the source type, or constructor overload resolution was ambiguous

然后当我将第一行替换为:

const QBrush *goldBrush = new QBrush(QColor(212,175,55));

消息仅略微更改为:

error: C2664: 'QGraphicsRectItem *QGraphicsScene::addRect(qreal,qreal,qreal,qreal,const QPen &,const QBrush &)' : cannot convert argument 6 from 'const QBrush *' to 'const QBrush &' Reason: cannot convert from 'const QBrush *' to 'const QBrush' No constructor could take the source type, or constructor overload resolution was ambiguous

最佳答案

你应该替换“scene->addRect(0,415,20,50,noPen,goldBrush);”使用“场景->addRect(0,415,20,50,noPen,*goldBrush);”。您这样做的方式是将地址传递到内存中的某个位置,而不是对变量的引用。

关于c++ - GraphicsView 上的 Qt QColor 和 QBrush?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34241002/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com