Results 1 to 9 of 9

Thread: Brush problems in GraphicsView

  1. #1
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Brush problems in GraphicsView

    Hi guys,

    I will try to be brief and concise:
    I fill polygon in the scene background with Qt::DensexPattern;
    My scene is a rect - > QRectF(QPOintF(-180,-90),QPointF(180,90));
    When I scale to see my small area(polygon) so that only 2x2 degrees there is a border scale over which the brush disappears; I zoom out -> the brush is visible;

    Maybe you had the same behaviour?

    Do you have any idea how to solve it? Maybe it is a Qt bug?
    I am using qt-4.4.0;

    To be precise I am using an image create from a bit table, and set my brush to fill polygon with that pixmap(image);
    All in all, the outcome is the same as with Qt::DensexPattern's;

    Beforehand thank you for any ideas.

    Kacper
    Last edited by jpn; 8th August 2008 at 16:57. Reason: disabled smilies
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  2. #2
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Brush problems in GraphicsView

    Maybe someone tested this "brush problem"?

    Kacper
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  3. #3
    Join Date
    Jul 2008
    Location
    East Coast, USA
    Posts
    40
    Thanks
    6
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Brush problems in GraphicsView

    This isn't a stippling issue is it, where a shade is created by a certain density of pixels, and when you zoom in enough, you start to miss the pixels? -K

  4. #4
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Brush problems in GraphicsView

    Hi,

    Maybe your ideas are good clues; I have a 2 dim array and have to select one of subarrays and use it as a fill pattern(brush pattern);
    I am doing it this way, I am not sure is it ok.

    I WOULD REALLY APPRECIATE ANY HELP.

    I am pasting a bit of code, to help you to help me : )
    Qt Code:
    1. static const char stipple_bits[12][8] =
    2. {
    3. { 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF },
    4. { 0x0018, 0x0018, 0x0018, 0x00FF, 0x00FF, 0x0018, 0x0018, 0x0018 },
    5. { 0x0049, 0x0092, 0x0024, 0x0049, 0x0092, 0x0024, 0x0049, 0x0092 },
    6. { 0x0000, 0x003c, 0x007e, 0x0066, 0x0066, 0x007e, 0x003c, 0x0000 },
    7. { 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 },
    8. { 0x00aa, 0x0055, 0x00aa, 0x0055, 0x00aa, 0x0055, 0x00aa, 0x0055 },
    9. { 0x0089, 0x0044, 0x0010, 0x0022, 0x0094, 0x0002, 0x0068, 0x0001 },
    10. { 0x0088, 0x0088, 0x0011, 0x0011, 0x0044, 0x0044, 0x0022, 0x0022 },
    11. { 0x003c, 0x0042, 0x00a5, 0x00a5, 0x0081, 0x00bd, 0x0042, 0x003c },
    12. { 0x0038, 0x0038, 0x0038, 0x0092, 0x007c, 0x0010, 0x0028, 0x006c },
    13. { 0x0054, 0x0029, 0x0084, 0x0029, 0x0080, 0x000c, 0x00a4, 0x0040 },
    14. { 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 }
    15. };
    16.  
    17. unsigned int fill_style = 2;
    18. /*! Creating the appropriate pattern*/
    19. QByteArray patternFillArray;
    20. patternFillArray.fromRawData(stipple_bits[fill_style],8);
    21.  
    22.  
    23. QImage image(QSize(8,8),QImage::Format_MonoLSB);
    24. image.loadFromData(patternFillArray);
    25. image.setColor(0,Qt::transparent);
    26.  
    27. ...
    To copy to clipboard, switch view to plain text mode 
    and sth like:
    image.setColor(1,Qt::red);/*!< Lets use RED color as fill color*/
    ..
    painter->setBrush(QBrush(image));
    painter->drawPOlygon(...);
    .....

    THANK YOU,

    Kacper
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  5. #5
    Join Date
    Jul 2008
    Location
    East Coast, USA
    Posts
    40
    Thanks
    6
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Brush problems in GraphicsView

    Well, as far as I see it, its merely a fact that your brush is not a vector brush but a bitmap. So at some point you end up seeing large pixels. I'm attaching the code I used below. Why excactly do you need to zoom in so close, and what kind of behavior are you expecting from this tiled bitmap? -K

    Qt Code:
    1. #include <iostream>
    2. #include <QtGui>
    3.  
    4. const char stipple_bits[12][8] =
    5. {
    6. { 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF, 0x00FF },
    7. { 0x0018, 0x0018, 0x0018, 0x00FF, 0x00FF, 0x0018, 0x0018, 0x0018 },
    8. { 0x0049, 0x0092, 0x0024, 0x0049, 0x0092, 0x0024, 0x0049, 0x0092 },
    9. { 0x0000, 0x003c, 0x007e, 0x0066, 0x0066, 0x007e, 0x003c, 0x0000 },
    10. { 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 },
    11. { 0x00aa, 0x0055, 0x00aa, 0x0055, 0x00aa, 0x0055, 0x00aa, 0x0055 },
    12. { 0x0089, 0x0044, 0x0010, 0x0022, 0x0094, 0x0002, 0x0068, 0x0001 },
    13. { 0x0088, 0x0088, 0x0011, 0x0011, 0x0044, 0x0044, 0x0022, 0x0022 },
    14. { 0x003c, 0x0042, 0x00a5, 0x00a5, 0x0081, 0x00bd, 0x0042, 0x003c },
    15. { 0x0038, 0x0038, 0x0038, 0x0092, 0x007c, 0x0010, 0x0028, 0x006c },
    16. { 0x0054, 0x0029, 0x0084, 0x0029, 0x0080, 0x000c, 0x00a4, 0x0040 },
    17. { 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 }
    18. };
    19.  
    20. class PaintMe : public QWidget
    21. {
    22. qreal scalex, scaley;
    23.  
    24. public:
    25. PaintMe(QWidget *parent = 0);
    26. void mousePressEvent (QMouseEvent *);
    27.  
    28. protected:
    29. void paintEvent(QPaintEvent *event);
    30.  
    31. };
    32.  
    33. PaintMe::PaintMe(QWidget *parent)
    34. : QWidget(parent)
    35. {
    36. setPalette(QPalette(QColor(250, 250, 200)));
    37. setAutoFillBackground(true);
    38. scalex = 1.0;
    39. scaley = 1.0;
    40. }
    41.  
    42. void PaintMe::paintEvent(QPaintEvent * /* event */)
    43. {
    44. unsigned int fill_style = 2;
    45. /*! Creating the appropriate pattern*/
    46. QByteArray patternFillArray;
    47. patternFillArray.fromRawData(stipple_bits[fill_style],8);
    48. QImage image(QSize(8,8),QImage::Format_MonoLSB);
    49. image.loadFromData(patternFillArray);
    50. image.setColor(1,Qt::red);
    51.  
    52. QPainter painter(this);
    53. painter.scale(scalex, scaley);
    54. painter.setBrush(QBrush(image));
    55. QRectF rectangle(0.0, 0.0, 500.0, 500.0);
    56. painter.drawRect(rectangle);
    57. }
    58.  
    59. void PaintMe::mousePressEvent (QMouseEvent *event) {
    60. switch(event->button()) {
    61. case Qt::LeftButton:
    62. scalex *= .7;
    63. scaley *= .7;
    64. std::cout << "Zoom out" << std::endl;
    65. break;
    66. case Qt::RightButton:
    67. scalex *= 1.2;
    68. scaley *= 1.2;
    69. std::cout << "Zoom in" << std::endl;
    70. break;
    71. }
    72. update();
    73. }
    74.  
    75. class Window : public QWidget
    76. {
    77. public:
    78. Window(QWidget *parent = 0);
    79. };
    80.  
    81. Window::Window(QWidget *parent)
    82. : QWidget(parent)
    83. {
    84. PaintMe *pm = new PaintMe(this);
    85. pm->setGeometry(10, 10, 480, 480);
    86. pm->show();
    87. }
    88.  
    89. int main(int argc, char *argv[])
    90. {
    91. QApplication app(argc, argv);
    92. Window window;
    93. window.setGeometry(100, 100, 500, 500);
    94. window.show();
    95. return app.exec();
    96. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Brush problems in GraphicsView

    Hi,

    My scene show the whole world map. When the user wants to read detailed info about particular part he/she chooses to read data and draw them; because the areas for which I load details are very small I need to scale to see the small part on the whole screen;
    Lets say that and anchorage area should be drawn using some kind of a brush, the brush is the one we are talking about.

    I will check the code you have pasted.
    I do not see pixels. Simply, at some point the brush disappears. I do not see larger pixels, but after zooming in few times everything is ok(brush is the same) and suddenly no brush is drawn over some scale.

    Kacper
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  7. #7
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Brush problems in GraphicsView

    Here is a sample of drawing, I need to achieve.
    There is a part of an island with some black lines and "stipple fill" brown parts.
    The "stipple fill" do not change while scaling.


    Kacper
    Attached Images Attached Images
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  8. #8
    Join Date
    Jul 2008
    Location
    East Coast, USA
    Posts
    40
    Thanks
    6
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Brush problems in GraphicsView

    Hi Maverick,

    The way I can think of doing what you want is to scale not the scene, but your own coordinates. So, if you have a polygon representing, say, Texas. Instead of doing "scale" in painter, you should scale the polygon coordinates yourself and then draw as usual. That way, regardless of the zoom level your stippling brush will have the same pixellation level.

    -K

  9. #9
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Brush problems in GraphicsView

    Hi,

    Yes that sounds ok, and have thought about this some time ago. For the time being I can't do that as 80% of the code is based on scene scaling. Still I need to find a solution to use the stipple brush.

    Kacper
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

Similar Threads

  1. GraphicsView performance problems
    By Gopala Krishna in forum Qt Programming
    Replies: 79
    Last Post: 8th August 2007, 17:32

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.