Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I draw with pen width of 0 (invisible not cosmetic)?

Tags:

c++

qt

drawing

I want to draw shapes with a border of various widths.

If I set width = 0 though, I expect (imagine) that here will be no border... yet I read that the border 0 is very thin ("cosmetic") border.

How can I draw my shapes with invisible border ?

int penWidth = 0; // some user input, 0 to 20 maybe
QPen pen = QPen(Qt::red, penWidth, Qt::PenStyle(Qt::SolidLine));
painter->setPen(pen);
painter->setBrush(QBrush(Qt::SolidPattern));
painter->drawRect(someRect);
like image 315
Thalia Avatar asked Mar 10 '15 15:03

Thalia


2 Answers

You can simply set no pen, i.e.:

painter->setPen(Qt::NoPen);

In this case it will not draw a border line at all.

like image 167
vahancho Avatar answered Oct 17 '22 03:10

vahancho


You can use the following to get an invisible QPen :

painter->setPen(QPen(Qt::NoPen));

The default QPen constructor creates a black solid line pen with 1 width, you have to force the style to Qt::NoPen to get an invisible one.

like image 3
tux3 Avatar answered Oct 17 '22 01:10

tux3