2

I'm using Qpainter to draw on a QWidget.

So, I have a QscrollArea about 1000 x 600 and a QPixmap inside. I would like to draw some segments (about 2000 lines) with QPainter on it. The QPixmap is very wide (about 150000)so I would like to do some optimization.

I have to do a lot of repaint for the pixmap. Inside of drawing the whole pixmap, I want to draw the part in the QscrollArea. I think that I can do it with controlling manually the horizontal scroll bar. But I wonder if there is some other Qt class can do the job for me? Maybe the QGraphicsView and QGrahpicsScene?

Mike Shaw
  • 373
  • 7
  • 22
  • Just curious, how did you manage to create that large QPixmap? – vahancho Mar 20 '14 at 15:34
  • @vahancho I know the max is something like 32768. The rest , I think, is not displayed. That's another reason why I have to do some optimization. – Mike Shaw Mar 20 '14 at 15:38
  • I would start from loading parts of the image with, for example, `QImageReader`, and painting that part on the visible part of `QScrollArea`. – vahancho Mar 20 '14 at 15:47
  • @vahancho Thanks for your comment. I'll try that at first. But I'm still curious about whether grahpicsview and grahpicsscene could do the same thing. It seems more simple. – Mike Shaw Mar 20 '14 at 15:54
  • @vahancho I forgot to mention that the I modify a lot the pixmap. The repaint costs very much. So I don't thing the QImageReader can solve the problem. Sorry for that I didn't explain myself. – Mike Shaw Mar 20 '14 at 16:05
  • how and where do you modify the pixmap? I think Qt is already smart enough to draw the visible part only. But you way want to use different tiles rather than one large pixmap – UmNyobe Mar 20 '14 at 16:10
  • @UmNyobe Actually, I modify the whole pixmap. But of cause, only the QscrollArea part is useful. I had the same thought but I found then the repaint when the area is focus on 200 lines costs the time when the area is on 2 lines. I think that the whole pixmap is drawn. But I'm not sure about that. – Mike Shaw Mar 20 '14 at 17:36
  • 1
    Instead of drawing the pixmap, draw on the widget and only draw the area that is displayed. QGraphicsScene would help you if you are lost or don't want to optimize this culling behaviour yourself. – user3427419 Mar 20 '14 at 17:41
  • @user3427419 Thanks for your comment. I think the cost is due to big pixmap that I create when repaint. Could you please give me some hints on how to draw directly on the widget. I tried QPainter painter(scrollArea) and QPainter painter(scrollArea->viewport()) in paintEvent(..). But the painter is always not active. – Mike Shaw Mar 21 '14 at 08:47
  • @MikeShaw you create a big pixmap when you repaint. why? Why dont you create only the part which is displayed. Show the code otherwise I can only speculate – UmNyobe Mar 21 '14 at 09:03
  • @UmNyobe Thanks for your comment. You are quite right. I don't have to create the whole pixmap. And that's why it is slow. – Mike Shaw Mar 21 '14 at 09:27
  • 1
    I'd definitely use the QGraphicsScene / View here. You can also set the view with QGLWidget to turn on OpenGL rendering, which is likely to be quicker too. If you're still having problems with speed, show code of what you're doing and we can look at how to optimise it. – TheDarkKnight Mar 21 '14 at 09:33

0 Answers0