Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. SizeHint() always returns default values

SizeHint() always returns default values

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 3.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Asperamanca
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Asperamanca
      wrote on last edited by
      #2

      Posted as bug:

      https://bugreports.qt-project.org/browse/QTBUG-24805

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved