Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drawing Rectangle with only 2 corners rounded in Qt

Tags:

qt

I am working on an application where I need to fill the color for the Pixmap using Painter. Pixmap is of type rectangle with (bottom edge) 2 rounded corners. Top 2 corners are flat/normal.

I tried to use the drawRoundedRect() API of Qt, but it makes all the corners of the rectangle rounded. I need to draw the rectangle with only 2 corners rounded and other two flat.

If anyone comes across the situation, please suggest me the solution.

Thanks

like image 287
user2111197 Avatar asked Mar 08 '13 07:03

user2111197


People also ask

Can a rectangle have rounded corners?

Definition of ROUNDED CORNER RECTANGLES:Labels that are rectangular in shape and have rounded corners; the corners do not form a sharp point, but instead are curved into an arc.

What is a rectangle called with rounded corners?

The word "squircle" is a portmanteau of the words "square" and "circle". Squircles have been applied in design and optics.


1 Answers

You can use QPainterPath for that :

    QPainterPath path;
    path.setFillRule( Qt::WindingFill );
    path.addRoundedRect( QRect(50,50, 200, 100), 20, 20 );
    path.addRect( QRect( 200, 50, 50, 50 ) ); // Top right corner not rounded
    path.addRect( QRect( 50, 100, 50, 50 ) ); // Bottom left corner not rounded
    painter.drawPath( path.simplified() ); // Only Top left & bottom right corner rounded
like image 152
Dimitry Ernot Avatar answered Sep 30 '22 19:09

Dimitry Ernot