×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Apr 2009
    Location
    Russia
    Posts
    51

    QPaintEvent optimizing

    Hello!
    I have developed some application, and now about optimizing it. It works well on device like N8, with graphic accelerator inside, but shows low frame rate on Nokia 5800. I have a QWidget with paintEvent:
    Code:
           QPainter p( this );
            p.drawPixmap(0,0,360,640,background);
            p.setRenderHint( QPainter::Antialiasing, true );
            p.translate( width()/2, height()/2 - cardposition-6);
            if (showanswer==false) p.setBrush(QColor(255,cardcolor,cardcolor, 180)); else p.setBrush(QColor(230,235, 255, 180));
            QRect rect;
            rect.setRect(-cardsize/2,-cardsize/2,cardsize,cardsize);
            p.drawRoundedRect(rect,8,8);
            if (!cardimage.isNull()) p.drawPixmap(-cardimage.width()/2,-cardimage.height()/2-14,cardimage); else {
                p.setPen(QColor(50,80, 125, 255));
                p.setFont(QFont("Arial", fontsize));
                rect.setRect(-cardsize/2+5,-cardsize/2+5,cardsize-10,cardsize-10);
                p.drawText(rect,Qt::AlignCenter|Qt::TextWordWrap,*cardtext);}
            p.setFont(QFont("Arial", 6));
            p.setPen(QColor(105,105, 105, 255));
            p.drawText(-150,150,*cardnumbertext);
            p.translate(-width()/2,-height()/2+cardposition);
            p.drawPixmap(0,0,QPixmap(QString::fromUtf8("://new/prefix1/edit.png")));
            p.translate(width()-56,0);
            p.drawPixmap(0,0,mode);
    Code paint background with a card at cardposition, and two button. And now if I only move a card for a few pixels my paintEvent is called automatically and completely repaint whole screen with background, buttons and card (if I understand correctly).
    How can I detach some paint objects and draw it only one time? I found a QPaintEvent ( const QRegion & paintRegion ), but dont understand how to use it. Will update(region) call QPaintEvent ( const QRegion & region)? Any suggestions are welcome!
    Thank in advance!

  2. #2
    Registered User
    Join Date
    May 2009
    Location
    Rome
    Posts
    268

    Re: QPaintEvent optimizing

    not sure if it fit your case anyway ...painter.setClipRegion(dirtyRect);
    Keep it simple, stupid
    borg - http://store.ovi.com/content/116105

  3. #3
    Nokia Developer Expert
    Join Date
    Feb 2008
    Posts
    183

    Re: QPaintEvent optimizing

    It might also make sense to put the background image to QPalette::Background as a texture brush and apply the palette to the QApplication, then you might forego the background painting in your paint event (depends on your app logic).
    QPainter::drawRoundedRect is somewhat expensive and might be faster to draw a pixmap with equivalent image instead.
    Text painting is also expensive - if you avoid that, it will help.

Similar Threads

  1. optimizing battery life tips?
    By rmanor in forum Symbian C++
    Replies: 5
    Last Post: 2009-12-23, 13:21
  2. Optimizing themes for E90 Communicator?
    By r2be in forum Themes/Carbide.ui
    Replies: 1
    Last Post: 2009-08-27, 12:27
  3. Optimizing Large Application....Please help.
    By sandeepsandeep in forum Mobile Java General
    Replies: 3
    Last Post: 2008-07-31, 19:01
  4. Optimizing j2me applications
    By scriptr in forum Mobile Java General
    Replies: 5
    Last Post: 2007-12-15, 15:33
  5. Optimizing J2ME application size
    By jnassif in forum Mobile Java General
    Replies: 2
    Last Post: 2002-05-17, 09:48

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •