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 circle with line pattern using QGraphicsScene

How to draw circle with line pattern using QGraphicsScene

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 5.3k 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.
  • M Offline
    M Offline
    mfaghani
    wrote on last edited by
    #1

    Hi there,
    I'm using QGraphicsScene and don't know how to draw a colored circle with horizantal line, vertical line, or other patern in a given color inside. The background of GraphicsView should be in a different color from circle and lines. Something like the image below.

    0_1547252642743_cont.png

    I need to change the lines' thickness and color, and color of the circle.
    Thank you.

    JKSHJ 1 Reply Last reply
    0
    • M mfaghani

      Hi there,
      I'm using QGraphicsScene and don't know how to draw a colored circle with horizantal line, vertical line, or other patern in a given color inside. The background of GraphicsView should be in a different color from circle and lines. Something like the image below.

      0_1547252642743_cont.png

      I need to change the lines' thickness and color, and color of the circle.
      Thank you.

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2
      • Draw a circle using a QGraphicsEllipseItem
      • Draw a line using a QGraphicsRectItem
      • You can enter the dimensions of the circle/line into their constructors, or change the dimensions by calling setRect()
      • Set the circle/line colour using setBrush()

      Most importantly, set the circle as the parent of the line and set the QGraphicsItem::ItemClipsChildrenToShape flag. This puts the line inside the circle, and clips the line to the circle's perimeter.

      const int DIAMETER = 100;
      auto circle = new QGraphicsEllipseItem(0, 0, DIAMETER, DIAMETER);
      circle->setFlag(QGraphicsItem::ItemClipsChildrenToShape, true);
      circle->setBrush(Qt::green);
      
      const int WIDTH = 10;
      const int LENGTH = DIAMETER;
      auto line = new QGraphicsRectItem(45, 0, WIDTH, LENGTH);
      line->setParentItem(circle);
      line->setBrush(Qt::black);
      
      auto scene = new QGraphicsScene;
      scene->addItem(circle);
      

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      5
      • M Offline
        M Offline
        mfaghani
        wrote on last edited by mfaghani
        #3

        It just works for me very well. I just used QGraphicsLineItem instead QGraphicsRectItem.
        Thank you in advance

        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