I have a custom QGraphicsWidgets which paints a few items and also contains some children proxy widgets:
//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);
}
My question is how would you add each component (drawing/widget) to a layout, and at what time would it be appropriate to do so? The term widgets refers to the QPushButton, QProgressBar, and QWebEngineView. Drawings refers to the shapes and text in the paint function.
Here is a sketch of how I would like the custom widget to look like: