0
votes

Can anyone point me to the right solution please with the following issue:

Got a QWidget, which is drawing a grid (simple lines) with QPainter. The size is set on a separate form (e.g.: 1024*1024 px with grid lines every 64 pixel)

The task is to get a scrollbar on the widget if the drawn grid is greater than the parent display area.

ui->setupUi(this);
m_mapDisplay.setParent(this);
ui->loMapDisplay->addWidget(ui->scrollArea);
ui->scrollArea->setWidget(&m_mapDisplay);
ui->scrollArea->setWidgetResizable(true);
ui->scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
1
Can't you just put your widget in a QScrollArea? - G.M.
Please put code in the question rather than in comments. Also, try setting the scroll bar policy for the vertical and/or horizontal scroll bars. - G.M.
With ScrollBarAlwaysOn I can see them, but the drawing is not taken into account. Maybe I need to add the scrollArea to the widget itself, not the parent? - Paxsentry
I've figured out if the minimumSize of the mapDisplay is set, than the scrollbars are displayed. The question now is how to set the minimumSize based on user selected values? (e.g.: 1024px 2048 px) - Paxsentry

1 Answers

0
votes

The solution that worked for me was to use setFixedSize(int x, int y)