Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Getting QScrollArea dimensions



  • I fail to get QScrollArea dimensions, I tried geometry(), width(), height() and others but I always get understimated dimensions of the real borders.
    Ho can I do?


  • Lifetime Qt Champion

    @willypuzzle said:
    you mean like
    QScrollArea f;
    f.viewport()->contentsRect();
    ?



  • I have this code:

    • centralWidgetContainer = new QScrollArea(this);
      CentralWidget* centralWidget = new CentralWidget(centralWidgetContainer);
      centralWidgetContainer->setWidget(centralWidget);
      centralWidgetContainer->setMinimumHeight(this->height() - centralWidgetContainerSizeGap);
      centralWidgetContainer->setMidLineWidth(this->width());

    When I try (from inside CentralWidget, that extends QFrame) something like:

    • QRect rect = ((QScrollArea*)this->parent())->viewport()->contentsRect();

    I got a rect with very understimate height and width values (respect this->height() and this->width() of the code above).


  • Lifetime Qt Champion

    well I think QMainwindow centralwidget have a default layout so
    maybe its the one altering the rect.

    Do you try to reserve some space or what is the purpose?


Log in to reply