Results 1 to 2 of 2

Thread: QGraphicsScene brush not working

  1. #1
    Join Date
    Mar 2010
    Location
    Auckland, NZ
    Posts
    121
    Thanks
    9
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default QGraphicsScene brush not working

    I've given up on trying to paint a QMdiArea, and instead I'm using the code below to paint on a scene -> view -> layout -> groupBox. Strangely, although I get a black rectangle, from the pen, the brush has no effect - I can't fill the rect.

    EDIT: I found the answer:
    brush.setStyle(Qt::SolidPattern);

    Qt Code:
    1. QVBoxLayout *layout = new QVBoxLayout();
    2. groupBox_test->setLayout(layout);
    3. QBrush brush;
    4. QPen pen;
    5. brush.setColor(Qt::red);
    6. pen.setColor(Qt::black);
    7. QGraphicsView *aview = new QGraphicsView(scene);
    8. layout->addWidget(aview);
    9. scene->addRect(0,0,50,50,pen,brush);
    10. aview->show();
    To copy to clipboard, switch view to plain text mode 
    Last edited by gib; 4th October 2018 at 01:58.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QGraphicsScene brush not working

    Oh yes, there's a third way to paint onscreen without a paint event, and that's to use the graphics / view architecture. In this case, the QGraphicsView::paintEvent() is doing the work of converting the scene graph into pixels.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 2
    Last Post: 4th April 2015, 17:32
  2. Replies: 1
    Last Post: 18th December 2009, 20:57
  3. something like colordialog, but with brush
    By Noxxik in forum Qt Programming
    Replies: 2
    Last Post: 22nd February 2009, 20:22
  4. Working with coordinates (QGraphicsScene/view)
    By maverick_pol in forum Qt Programming
    Replies: 5
    Last Post: 27th March 2008, 08:35
  5. QPalette::brush
    By tpf80 in forum Newbie
    Replies: 6
    Last Post: 17th July 2007, 23:23

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.