View Single Post
pichlo's Avatar
Posts: 6,445 | Thanked: 20,981 times | Joined on Sep 2012 @ UK
#4
Is reviving a 3yo thread better or worse than creating a new one?

Anyway, I have a QScrollArea that covers most of the screen. Inside it, I have a widget of type Preview, derived from QGLWidget.

I also have zoom buttons. Zoom affects the horizontal size only, the vertical dimension is fixed. The problem is that zooming in more than two times segfaults the program.

Here is the relevant bit where it segfaults:
Code:
void Preview::paintGL ()
{
  QPainter painter(this);
  painter.setRenderHint(QPainter::Antialiasing, true);

  const int w = width();
  const int h = height();

  // Paint the background
  painter.fillRect(0, 0, w, h, Qt::white);

  // ... a few dozen more lines ...

  painter.end();
}
It crashes on the painter.fillRect line, as verified by sticking qDebug before and after. Values of w and h were:

w=668, h=416, OK (starting point)
w=1002, h=416, OK (zoom in x1)
w=1503, h=416, OK (zoom in x2)
w=2254, h=416, crash!

What is going on? Can the device not handle painting areas of that size? (Code written, built and run entirely on the phone.)

Given the experience, I am inclined to rewrite the code to eliminate QScrollArea altogether and instead do my own redrawing the preview with moving starting point. What options do I have to drag the picture left or right with the finger? I would really prefer not to try implementing my own version of kinetic scrolling if I can.
 

The Following 2 Users Say Thank You to pichlo For This Useful Post: