0

我有一个自定义的 QGraphicsWidgets ,它绘制了一些项目,还包含一些子代理小部件:

//Constructor adds a child proxy button
TestWidget::TestWidget(QJsonObject testDefinition, QJsonObject testStatus, QString parentSequenceID, QGraphicsWidget *parent):
    m_parentID(parentSequenceID),
    m_testStatus(testStatus),
    m_testDefinition(testDefinition)
{
    Q_UNUSED(parent);

    m_name = m_testDefinition[displayNameStr].toString();
    m_status = m_testStatus[resultStr].toObject()[resultStr].toString();
    m_id = m_testDefinition[idStr].toString();

    m_layout = new QGraphicsLinearLayout(Qt::Vertical, this);

    //Add the pause/resume button
    auto *proxyPauseAbortButton = new QGraphicsProxyWidget(this);

    proxyPauseAbortButton->setWidget(new QPushButton(tr("Pause")));
    proxyPauseAbortButton->moveBy(20, 40);

    //Add the progress bar
    auto * proxyTestProgressBar = new QGraphicsProxyWidget(this);
    QProgressBar * testProgressBar = new QProgressBar();
    testProgressBar->setOrientation(Qt::Horizontal);
    testProgressBar->setRange(0, 100); // Let's say it goes from 0 to 100
    testProgressBar->setValue(10); // With a current value of 10

    proxyTestProgressBar->setWidget(testProgressBar);
    proxyTestProgressBar->moveBy(20, 80);

    //Add the html view
    auto * proxyTestHtmlView = new QGraphicsProxyWidget(this);
    QWebEngineView * testHtmlView = new QWebEngineView();
    testHtmlView->load(QUrl(QStringLiteral("https://www.google.com/")));

    proxyTestHtmlView->setWidget(testHtmlView);
    proxyTestHtmlView->moveBy(20, 120);

}

//Paint function draws a border, shapes, and text
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);

}

我的问题是如何将每个组件(绘图/小部件)添加到布局中,什么时候这样做合适?术语小部件指的是 QPushButton、QProgressBar 和 QWebEngineView。绘图是指绘图功能中的形状和文本。

这是我希望自定义小部件看起来如何的草图: 在此处输入图像描述

4

0 回答 0