Results 1 to 3 of 3

Thread: QBrush pattern problem

  1. #1
    Join Date
    Jul 2006
    Posts
    1
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QBrush pattern problem

    When window size is changed by using QPainter:: setWindow(...)
    during a zooming process, the behaviour of brush pattern is very
    wierd (please look at the attached bmp). Is there any way to make
    the brush pattern stable?

    //Painting codes:

    void paint_test:: paintEvent(QPaintEvent * e)
    {
    QPainter painter(this);
    painter.setPen(Qt::red);

    QBrush brush(Qt:: Dense6Pattern);
    brush.setColor(Qt::blue);
    painter.setBrush(brush);

    painter.setWindow(0, 0, 1000, 1000);
    painter.drawRect(50, 50, 100, 200);

    painter.setWindow(0, 0, 2000, 2000);
    painter.drawRect(500, 100, 200, 400);

    painter.setWindow(0, 0, 3000, 3000);
    painter.drawRect(1350, 150, 300, 600);

    painter.setWindow(0, 0, 4000, 4000);
    painter.drawRect(2600, 200, 400, 800);

    painter.setWindow(0, 0, 5000, 5000);
    painter.drawRect(4250, 250, 500, 1000);
    }
    Attached Images Attached Images

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QBrush pattern problem

    Indeed, it behaves strange. Especially when you resize the widget. It might be a result of some round-off errors, but IMO you should show this example to the Trolls.

    Below is a working example:
    Qt Code:
    1. #include <QApplication>
    2. #include <QPainter>
    3. #include <QWidget>
    4.  
    5. class Test : public QWidget
    6. {
    7. protected:
    8. void paintEvent( QPaintEvent * )
    9. {
    10. QPainter painter(this);
    11. painter.setPen(Qt::red);
    12.  
    13. QBrush brush(Qt:: Dense6Pattern);
    14. brush.setColor(Qt::blue);
    15. painter.setBrush(brush);
    16.  
    17. painter.setWindow(0, 0, 1000, 1000); // try to comment out this line
    18. painter.drawRect(50, 50, 100, 200);
    19.  
    20. painter.setWindow(0, 0, 2000, 2000);
    21. painter.drawRect(500, 100, 200, 400);
    22.  
    23. painter.setWindow(0, 0, 3000, 3000);
    24. painter.drawRect(1350, 150, 300, 600);
    25.  
    26. painter.setWindow(0, 0, 4000, 4000);
    27. painter.drawRect(2600, 200, 400, 800);
    28.  
    29. painter.setWindow(0, 0, 5000, 5000);
    30. painter.drawRect(4250, 250, 500, 1000);
    31. }
    32. };
    33.  
    34. int main( int argc, char **argv )
    35. {
    36. QApplication app( argc, argv );
    37.  
    38. Test t;
    39. t.show();
    40.  
    41. return app.exec();
    42. }
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to jacek for this useful post:

    ilovethisgame (10th July 2006)

  4. #3
    Join Date
    Apr 2012
    Posts
    1
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QBrush pattern problem

    6 years later... I ran into this same problem, and only found this post referring to it. I solved it by doing the following:

    Qt Code:
    1. painter.setWindow(0,0,_logicalWidth,_logicalHeight); //setting the logical window
    2.  
    3. QBrush brush(Qt::blue,Qt::Dense6Pattern);
    4.  
    5. //add a transform to the brush to undo the logical scaling
    6. brush.setTransform( QTransform::fromScale( width()/_logicalWidth, height()/_logicalHeight) );
    7.  
    8. painter.setBrush(brush);
    9.  
    10. //and carry on drawing
    To copy to clipboard, switch view to plain text mode 

    Hopefully this helps anyone who stumbles across it!

Similar Threads

  1. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 12:54
  2. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  3. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 14:08
  4. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.