1
QBrushを使用してsetBrushで5 QGraphicsRectItemのブラシを設定しようとしています。それは動作しません。場合によっては動作が混乱します。QGraphicsSceneでQGraphicsRectItemのブラシを設定する方法
コードは、私はQtの-Creatorで作成した*の.uiが含まれています。私はそれにQGraphiocsViewを追加しました。
QGraphicsScene *scene_;
scene_ = new QGraphicsScene(ui->graphicsView);
ui->graphicsView->setScene(scene_);
scene_->setBackgroundBrush(Qt::red);
for (int i=0; i<5; i++)
{
QBrush tmpBrush;
tmpBrush.setColor(QColor(200-i*15, i*15, 50));
QPen tmpPen;
tmpPen.setColor(Qt::blue); tmpPen.setWidth(2);
QGraphicsRectItem*tmpRect = scene_->addRect(2, 25*i, 100, 20, tmpPen, tmpBrush);
tmpRect->setPen(tmpPen); tmpRect->setBrush(tmpBrush);
}
私はUbuntu 16.04でQT 5.7でコーディングしています。
ありがとうございました!これは参考になり、コードは正しく実行されています –