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. QPainter trick .
Qt 6.11 is out! See what's new in the release blog

QPainter trick .

Scheduled Pinned Locked Moved Solved General and Desktop
qpainter
6 Posts 2 Posters 2.5k Views 2 Watching
  • 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.
  • W Offline
    W Offline
    Walux
    wrote on last edited by Walux
    #1

    Hi Qt Community ,

    I tried countless times to create a certain shape but i failed :

    I want to draw a "donut"-like shape whose center is transparent , so i tried something like this , but it was in vain :

    painter->setBrush(MyColor);
    painter->drawEllipse(QPointF(0,0),10,10);
    painter->setBrush(Qt::NoBrush);
    painter->drawEllipse(QPointF(0,0),6,6);
    

    Any ideas ?

    Taking things from beginning to end : That's my entertainment !

    ? 1 Reply Last reply
    0
    • W Walux

      Hi Qt Community ,

      I tried countless times to create a certain shape but i failed :

      I want to draw a "donut"-like shape whose center is transparent , so i tried something like this , but it was in vain :

      painter->setBrush(MyColor);
      painter->drawEllipse(QPointF(0,0),10,10);
      painter->setBrush(Qt::NoBrush);
      painter->drawEllipse(QPointF(0,0),6,6);
      

      Any ideas ?

      ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      @Walux said:

      Any ideas ?

          QPainterPath path;
          path.addEllipse(0, 0, 400, 400);
          path.addEllipse(50,50,300,300);
          painter->setRenderHint(QPainter::Antialiasing);
          painter->setBrush( QBrush(QColor("black")) );
          painter->drawPath(path);
      
      W 1 Reply Last reply
      2
      • ? A Former User

        @Walux said:

        Any ideas ?

            QPainterPath path;
            path.addEllipse(0, 0, 400, 400);
            path.addEllipse(50,50,300,300);
            painter->setRenderHint(QPainter::Antialiasing);
            painter->setBrush( QBrush(QColor("black")) );
            painter->drawPath(path);
        
        W Offline
        W Offline
        Walux
        wrote on last edited by
        #3

        @Wieland

        Works like a charm !
        I wonder why this worked !

        Taking things from beginning to end : That's my entertainment !

        ? 1 Reply Last reply
        0
        • W Walux

          @Wieland

          Works like a charm !
          I wonder why this worked !

          ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          @Walux said:

          I wonder why this worked

          See QPainterPath Class, especially note:

          Finally we draw the entire path. The path is filled using the default fill rule, Qt::OddEvenFill.

          Qt::OddEvenFill

          Specifies that the region is filled using the odd even fill rule. With this rule, we determine whether a point is inside the shape by using the following method. Draw a horizontal line from the point to a location outside the shape, and count the number of intersections. If the number of intersections is an odd number, the point is inside the shape. This mode is the default.

          W 1 Reply Last reply
          2
          • ? A Former User

            @Walux said:

            I wonder why this worked

            See QPainterPath Class, especially note:

            Finally we draw the entire path. The path is filled using the default fill rule, Qt::OddEvenFill.

            Qt::OddEvenFill

            Specifies that the region is filled using the odd even fill rule. With this rule, we determine whether a point is inside the shape by using the following method. Draw a horizontal line from the point to a location outside the shape, and count the number of intersections. If the number of intersections is an odd number, the point is inside the shape. This mode is the default.

            W Offline
            W Offline
            Walux
            wrote on last edited by
            #5

            @Wieland

            Very informative :)
            U have my precious thanks ;)

            Taking things from beginning to end : That's my entertainment !

            ? 1 Reply Last reply
            0
            • W Walux

              @Wieland

              Very informative :)
              U have my precious thanks ;)

              ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #6

              @Walux :-)

              1 Reply Last reply
              0

              • Login

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