我想在我的 QGraphicswidget 中嵌入一个 QWidget,例如按钮或进度条,但我只看到了将 QWidget 添加到 QGraphicsScene 的示例,即
m_scene->addWidget(new QPushButton("Test Test"));
在我的自定义图形小部件中,我正在绘制函数中绘制文本和其他自定义形状。我认为您需要在此处添加 QWidget,但我可能错了。有谁知道如何做到这一点?
这是我重载的绘画功能:
void TestWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem
*option, QWidget *widget /*= 0*/)
{
Q_UNUSED(widget);
Q_UNUSED(option);
QRectF frame(QPointF(0,0), geometry().size());
QGradientStops stops;
//Draw border
painter->drawRoundedRect(boundingRect(), 5.0, 5.0);
//Name of the test
painter->drawText(40, 20, m_name);
//Status of test
QFont font = painter->font() ;
font.setPointSize(14);
painter->setFont(font);
painter->drawText(600, 20, m_status);
//Arrow button
QPolygonF poly;
poly << QPointF(5, 10) << QPointF(25, 10) << QPointF(15, 20 )<<
QPointF(5,10);
painter->setBrush(Qt::black);
painter->drawPolygon(poly, Qt::OddEvenFill);
}