Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to draw filled polygon on QGraphicsScene

How to draw filled polygon on QGraphicsScene

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 1 Posters 6.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • chuanlauC Offline
    chuanlauC Offline
    chuanlau
    wrote on last edited by
    #1

    I want to draw a polygon filled with a specific color on QGraphicsScene. Then I use the following codes:

    QPolygonF poly;
    poly << QPointF(10, 10) << QPointF(10, 50) << QPointF(30, 70 )<< QPointF(60, 50) << QPointF(50, 10);
    QBrush brush;
    brush.setColor(Qt::red);
    QPen pen(Qt::green);
    QGraphicsScene graphics_scene_ = new QGraphicsScene(0,0,200,200);
    graphics_scene_->addPolygon(poly, pen, brush);
    setScene(graphics_scene_);
    

    However I only get a hollow polygon with green border, but without red fill inside the polygon.
    How can I fix it?

    1 Reply Last reply
    0
    • chuanlauC Offline
      chuanlauC Offline
      chuanlau
      wrote on last edited by
      #2

      I've finally figured out how to do.
      Just adding

      brush.setStype(Qt::SolidPattern);
      

      works.

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved