I want to write a custom control (something like a hexviewer). It has a very large client area, so it needs scroll bars. so derived a class from QScrollArea and called the SetWidget method. The following are my doubts...
how can I set the size of client area (for drawing) ? is it by using resize() call? When I call resize, the whole window gets resized, how can I make it show the scrollbars?
is it possible to set the width and height of client area in 64bits (long long) than in 32bits?
tucnak last edited by
AFAIN, in QAbsractScrollArea you can draw on widget without any restrictions. It will automatic create scroll bars.
- With QWidget::setSize(QSise&)
- No. QWidget use int.
I too have been searching for the method QWidget::setSize(). But, unfortunately could not find any!! Am i wrong?
goetz last edited by
You call setWidget() with some other widget. You need to resize that one, not the scroll area widget. For example:
QScrollArea *area = new QScrollArea;
QLabel *clientWidget = new QLabel(area);
// ... later on
ObiWan last edited by
If your client widget has a layout, fill your layout with your widgets and call:
andre last edited by
If you have a huge client area, like you may have for a hex viewer, I recommend against using a separate widget as the viewer inside a QScrollArea. This solution is very nice for forms that extend beyond the screen size on small screens of something like that, but not for potentially huge views.
Take a hint from how the Qt item view classes are implemented instead. They derive from QAbstractScrollArea, and take care of the rendering of the client area themselves. That is really the only way to go without getting into immediate problems with coordinate systems. Note that the actual width and height of your widgets may, depending on the underlying system, be actually much more constrained than the 32 bits limit you see. Think 16 bits unsigned... That is not a Qt limitation, but a limitation of the underlying system in that case. You circumvent this issue if you don't try to put a huge viewing widget inside a QScrollArea, but do your own rendering instead.
If you then also take the position of the scrollBar as indicating the actual row, rather than the top pixel row, you can display 2^31 rows of items (note that the scrolbar uses an integer for its position, not an unsigned integer). If that is not enough, than you really need to think of a different way of navigating your content, as a scrollbar is not going to help the user anymore long before you reach that limit. Every pixel of the scrollbar on the screen (using the full screen height, even on the new Retina MacBooks!) is going to represent more than a million lines of data in your view.
Thanks a lot. I was looking for an elegant solution like this.