QScrollArea how to question (inactive scrollbars) [solved]
I have a class named avl_widget, the class can draw binary tree data structures. I want to make it to be scrollable. In the example I use only a QLabel.
class AVL_draw : public QWidget
explicit AVL_draw(QWidget parent = 0);
#endif // ALV_DRAW_H@
AVL_draw::AVL_draw(QWidget *parent) :
painter.drawRect(0,0, this->width(), this->height());
The parent widget has a layout:
class AVL_widget : public QWidget
explicit AVL_widget(QWidget* parent = 0);
#endif // AVL_WIDGET_H
AVL_widget::AVL_widget(QWidget *parent) :
//main.addWidget(&draw); draw_scrollarea.setGeometry(draw.geometry()); draw_scrollarea.setWidget(&draw); draw_scrollarea.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); draw_scrollarea.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn); draw_scrollarea.setWidgetResizable(true); main.addWidget(&draw_scrollarea); main.addLayout(&buttons_bottom);
The scollbars are disabled, but the label is out of range. What is the problem?
You just put it at that fixed position and never update its position or size. Since you don't put it in layout, it's your job to do it. But since your label only contains X and you are painting the widget yourself, why not draw the X yourself at the right place ?
On a side note, you should use pointers to your widgets/layouts
Which function can update the position and size?
I accept your hint, that paint the X to the correct place, I only used QLabel to simplify the code. If I paint graphes with painter to widget, I can not scrolling it too.
What is the reason that I should use pointers to widgets/layouts?
Many thanks SGaist!
The resize function for example.
Have a look at the "Basic drawing example" it should help you get started.
As for why you should rather do heap allocation see "this ":http://qt-project.org/forums/viewthread/2962 thread. More specifically the answer from peppe from the 4th january 2011
Unfortunately I could not correct the code. I read more examples but I can not see the problem.
After that I used the setMinimumSize() it works. Before the widget has autosizing.