Results 1 to 2 of 2

Thread: QGraphicsItem filling with pattern

  1. #1
    Join Date
    Jul 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QGraphicsItem filling with pattern

    Hello,

    I'd like to fill a QGraphicsItem with a pattern specified by a bitmap. Just like Qt::SolidPattern, Qt::Dense1Pattern, but a custom defined one.

    For now I've tried drawing a QBitmap for the pattern with only black and white, and appliy this to a QBrush with a color. But the pattern doesnt draw correctly on the screen, and also I get this error:

    QBrush: Incorrect use of TexturePattern

    On MacOS the items are not filled, and in Windows and Linux the filling is not correct and it breaks when zooming, for example.

    The code I used to create the brush is the following:

    Qt Code:
    1. QBitmap *texture = createBrushFromPacket(layerPacket);
    2. QColor fillColor = QColor::fromRgb(r, g, b);
    3.  
    4. QBrush fillBrush(fillColor, Qt::TexturePattern);
    5. fillBrush.setTexture(*texture);
    6. fillBrush.setColor(fillColor);
    To copy to clipboard, switch view to plain text mode 

    createBrushFromPacket returns the bitmap, and r, g, b contain the RGB color values.

    Later on my code, when I draw the QGraphicsItem I do the following:

    Qt Code:
    1. QGraphicsEllipseItem *item = new QGraphicsEllipseItem(rx, ry, radius, radius);
    2.  
    3. item->setBrush(fillBrush);
    4. item->setPen(fillColor);
    To copy to clipboard, switch view to plain text mode 

    What am I doing wrong?

    Thanks in advance,

    Francesc Vila

  2. #2
    Join Date
    Jul 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsItem filling with pattern

    I have resolved the "QBrush: Incorrect use of TexturePattern" error using:

    Qt Code:
    1. QBrush fillBrush(fillColor, *texture);
    To copy to clipboard, switch view to plain text mode 

    and later, when adding an item:

    Qt Code:
    1. QGraphicsEllipseItem *item = new QGraphicsEllipseItem(rx, ry, radius, radius);
    2.  
    3. item->setBrush(fillBrush);
    4. item->setPen(fillColor);
    To copy to clipboard, switch view to plain text mode 

    But the pattern still does not show correctly. In fact, in MacOSX with Qt 4.7, the items are not filled.

    Anyone knows the correct way to create filling patterns?

    Regards,

    Francesc

Similar Threads

  1. Filling QPixmap as progressbar
    By NoRulez in forum Qt Programming
    Replies: 1
    Last Post: 12th October 2009, 17:01
  2. Filling a QGraphicsItem
    By c_srikanth1984 in forum Qt Programming
    Replies: 15
    Last Post: 6th July 2009, 14:34
  3. Filling forms with QWebKit
    By physicistjedi in forum Qt Programming
    Replies: 1
    Last Post: 4th December 2008, 18:50
  4. Filling an image
    By Caius Aérobus in forum Qt Programming
    Replies: 6
    Last Post: 6th July 2008, 21:13
  5. filling scrollview
    By illuzioner in forum Qt Programming
    Replies: 1
    Last Post: 17th February 2006, 22:00

Tags for this Thread

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.