June 16, 2012

lloydqt lloydqt
Lab Rat
38 posts

Custom control

 

Hi,

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…

1) 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?

2) is it possible to set the width and height of client area in 64bits (long long) than in 32bits?

Thanks, Lloyd

6 replies

June 16, 2012

tucnak tucnak
Robot Herder
384 posts

AFAIN, in QAbsractScrollArea you can draw on widget without any restrictions. It will automatic create scroll bars.

1) With QWidget::setSize(QSise&)
2) No. QWidget use int.

 Signature 

Qt Developer (upper-intermediate)
PHP/JS Developer (intermediate)

June 16, 2012

lloydqt lloydqt
Lab Rat
38 posts

I too have been searching for the method QWidget::setSize(). But, unfortunately could not find any!! Am i wrong?

June 23, 2012

Volker Volker
Robot Herder
5428 posts

You call setWidget() with some other widget. You need to resize that one, not the scroll area widget. For example:

  1. QScrollArea *area = new QScrollArea;
  2. QLabel *clientWidget = new QLabel(area);
  3. area->setWidget(clientWidget);
  4.  
  5. // ... later on
  6.  
  7. clientWidget->resize(1000,5000);

June 23, 2012

ObiWan ObiWan
Lab Rat
6 posts

If your client widget has a layout, fill your layout with your widgets and call:

  1. clientWidget->setMinimumSize(clientWidgetLayout->sizeHint());

June 25, 2012

Andre Andre
Area 51 Engineer
6031 posts

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.

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

June 25, 2012

lloydqt lloydqt
Lab Rat
38 posts

Thanks a lot. I was looking for an elegant solution like this.

 
  ‹‹ [SOLVED] Simple socket client inside app      error: incomplete type ’QTime’ used in nested name specifier[solved] ››

You must log in to post a reply. Not a member yet? Register here!