There is a window with custom widgets-diagrams and widgets-time-scales: Window with charts Initially, the size of the widget-digram is set in the constructor as follows relative to its scroll, in which the widget is located:

setGeometry(0, 0, max<int>(static_cast<int>(outputData->maxArrivingTime() / dialog->commonSAGridSpacing * dialog->commonSAScale) + 20, parent->width()), max<int>(static_cast<int>(outputData->outputSettings.flowQuantity * (rowHeight + 1)), parent->height())); 

Then, using the buttons for controlling the grid spacing in time ( gridaSpacing ) and the scale in pixels ( scale ), the diagram is redrawn, it is set to the geometry in the redrawing method:

 setGeometry(0, 0, max<int>(static_cast<int>(outputData->maxArrivingTime() / dialog->commonSAGridSpacing * dialog->commonSAScale) + 20, dynamic_cast<QScrollArea *>(parent())->width()), max<int>(static_cast<int>(outputData->outputSettings.flowQuantity * (rowHeight + 1)), dynamic_cast<QScrollArea *>(parent())->height())); 

Gradually with breakpoints, the widget's geometry becomes larger than the scroll geometry, the parents are specified neatly, but the widget does not scroll, scroll bars do not appear, although setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded) .

    1 answer 1

    Initially, the scroll area did not have the setWidget() method, but the widget had its parent set the parent - the desired scroll area. The setWidget() method notifies the parent that the child has resized, forcing the parent to analyze the size of the child relative to his own.

    Also in the redraw method was the setGeomtry method was replaced by resize .