Results 1 to 6 of 6

Thread: Creating an Icon-Editor

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Join Date
    Dec 2009
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Creating an Icon-Editor

    Hi,

    I know, that paintEvent() repainted the whole area, even if just one pixel changed.

    Now, paintEvent() looks like this:
    Qt Code:
    1. void IconEditor::paintEvent(QPaintEvent *event)
    2. {
    3. QPainter painter(this);
    4.  
    5. QRect updateRect = event->rect();
    6. updateRect = QRect(updateRect.topLeft() / zoom, updateRect.size() / zoom);
    7.  
    8. for(int i = updateRect.left(); i <= updateRect.right(); ++i) {
    9. if(!image.rect().contains(i, 0)) break;
    10. for(int j = updateRect.top(); j <= updateRect.bottom(); ++j) {
    11. if(!image.rect().contains(0, j)) break;
    12. QRect rect = pixelRect(i, j);
    13. if(!event->region().intersect(rect).isEmpty()) {
    14. QColor color = QColor::fromRgba(image.pixel(i, j));
    15. if(color.alpha() < 255)
    16. painter.fillRect(rect, color);
    17. painter.fillRect(rect, color);
    18. }
    19. }
    20. }
    21. }
    To copy to clipboard, switch view to plain text mode 

    So, only the part that changed is repainted. But it's still not possible to paint a continuous line.

    Is there a better way to implement paintEvent()?
    Attached Images Attached Images

Similar Threads

  1. Replies: 2
    Last Post: 12th October 2008, 14:42
  2. Couple of questions: main window icon + toolbar icon
    By bpackard in forum Qt Programming
    Replies: 0
    Last Post: 20th March 2008, 19:03
  3. Replies: 1
    Last Post: 17th January 2008, 10:17
  4. QTableWidget and creating my own editor
    By macias in forum Qt Programming
    Replies: 1
    Last Post: 13th June 2007, 11:02
  5. Creating simple text editor from the eamples code
    By overcast in forum Qt Programming
    Replies: 4
    Last Post: 14th February 2007, 15:46

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.