SizeHint() always returns default values
-
I have a QGraphicsWidget subclass, which is managed in a QGraphicsGridLayout.
The subclass calls setMinimumSize(68, 34) and setSizePolicy (Horizontal: MinimumExpanding, Vertical: Minimum).
My problem is that the layout did not honor this minimum size. A couple of hours debugging and tracing later, I realized that every call to QGraphicsWidget::sizeHint(Qt::MinimumSize) always returns QSizeF(0,0) instead of the size I had set previously.
I traced by subclassing sizeHint this way:
@QSizeF CGlib_GraphicsTimeScaleWidget::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
{
QSizeF size = QGraphicsWidget::sizeHint(which, constraint);qDebug() << "TimeScaleWidget::sizeHint" << "which:" << which << "constraint:" << constraint << "resulting sizeHint:" << size; return size;
}@
The results:
@TimeScaleWidget::sizeHint which: 2 constraint: QSizeF(-1, -1) resulting sizeHint: QSizeF(1.67772e+07, 1.67772e+07)
TimeScaleWidget::sizeHint which: 0 constraint: QSizeF(-1, -1) resulting sizeHint: QSizeF(0, 0)
TimeScaleWidget::sizeHint which: 1 constraint: QSizeF(-1, -1) resulting sizeHint: QSizeF(50, 50)
Updating minimum size to QSizeF(68, 34) size policy to horiz: 3 vert: 1
TimeScaleWidget::sizeHint which: 2 constraint: QSizeF(-1, -1) resulting sizeHint: QSizeF(1.67772e+07, 1.67772e+07)
TimeScaleWidget::sizeHint which: 1 constraint: QSizeF(-1, -1) resulting sizeHint: QSizeF(50, 50)
TimeScaleWidget::sizeHint which: 0 constraint: QSizeF(-1, -1) resulting sizeHint: QSizeF(0, 0) @After the "Updating minimum size" call, I would expect the minimum size to return QSizeF(68, 34).
When debugging into qgraphicswidget.cpp, I see that for my object, d->layout is Null. How can that be? The object is inside a grid layout, and I can see it's position is managed by the layout (I don't otherwise set the object's size and position). But because d->layout is Null, I only get the default values for size hints, instead of the minimum size I set myself.
For the sake of completeness, here is the content of my layout:
@
m_pMainLayout->addItem(m_pAnalogLegend,0,0,2,1);
m_pMainLayout->addItem(m_pDateLabel,2,0);
m_pMainLayout->addItem(m_pBinaryLegend,3,0,1,2);
m_pMainLayout->addItem(m_pValueScale,0,1);
m_pMainLayout->addItem(m_pAnalogCurveCanvas,0,2);
// This is the item I am tracing
m_pMainLayout->addItem(m_pTimeScale,1,2,2,1);
//
m_pMainLayout->addItem(m_pBinaryCurveCanvas,3,2,1,1);
m_pMainLayout->addItem(m_pButtonBar,4,0,1,3);@Any ideas what might go wrong here?
-
Posted as bug: