PDA

View Full Version : QRect without Border



rohitkk
27th June 2014, 09:25
Hi All,
Is there any way to hide/erase the border of the QRect.

anda_skoa
27th June 2014, 10:16
Since a QRect is just a data class and has no visualization, how are you drawing the rectange?

Cheers,
_

rohitkk
27th June 2014, 10:36
Since a QRect is just a data class and has no visualization, how are you drawing the rectange?

Cheers,
_

I am drawing it on the pdf using QPainter on QPrinter.



QPrinter reportPrinter;
QPainter reportPainter;

//SETTING PDF FORMAT
reportPrinter.setOutputFormat(QPrinter::PdfFormat) ;

//DRAWING RECTANGLE ON THE PDF
QRect rect = QRect(0,50,30,20);
reportPainter.drawRect(rect );
reportPainter.drawText(rect , Qt::AlignCenter | Qt::TextWordWrap, "SOME TEXT INSIDE");

I want to draw QRect rect without borders.

yeye_olive
27th June 2014, 10:47
If you RTFM of QPainter::drawRect(), you will see that it uses the current pen and the current brush. The pen is what controls how the border is drawn. Just set the appropriate pen, then.

rohitkk
27th June 2014, 11:11
If you RTFM of QPainter::drawRect(), you will see that it uses the current pen and the current brush. The pen is what controls how the border is drawn. Just set the appropriate pen, then.

Thanks for the reply,
I have just written the below LOC for setting the width of the QPen just before the QRect,




QPen pen=reportPainter.pen();
pen.setWidth(0);
reportPainter.setPen(pen);

//DRAWING RECTANGLE ON THE PDF
QRect rect = QRect(0,50,30,20);
reportPainter.drawRect(rect );
reportPainter.drawText(rect , Qt::AlignCenter | Qt::TextWordWrap, "SOME TEXT INSIDE");



But this isn't helping. It is drawing the rectangle with the same width (as it was before writing above LOC for setting the width of QPen).

yeye_olive
27th June 2014, 11:18
Again, the doc for QPen says it all: "A line width of zero indicates a cosmetic pen. This means that the pen width is always drawn one pixel wide, independent of the transformation set on the painter."

Qt's documentation is great. I suggest you read the whole documentation of the classes you use before posting here. That is what I just did; I had never drawn a rectangle in a QPainter but I found the answers to your questions there.

rohitkk
27th June 2014, 11:28
Again, the doc for QPen says it all: "A line width of zero indicates a cosmetic pen. This means that the pen width is always drawn one pixel wide, independent of the transformation set on the painter."

Qt's documentation is great. I suggest you read the whole documentation of the classes you use before posting here. That is what I just did; I had never drawn a rectangle in a QPainter but I found the answers to your questions there.

Yeah I have been reading the document, but partially.
This means there is no way to do so.
Right?

^NyAw^
27th June 2014, 11:35
Hi,

Are you sure that now have you readed all QPen Doc?
It tooks me only 30 seconds to discover that the pen have a style, and you can set it to "no pen".

yeye_olive
27th June 2014, 11:43
Yeah I have been reading the document, but partially.
This means there is no way to do so.
Right?
Shame on you. I just told you to read the documentation and you keep spamming the forum without doing so; yes, that means reading the whole page. The answer to your question is right there. Had you put as much effort into solving your own problem as I have, this whole thing would have been over an hour ago.

OK, now that someone has given a major clue, I might as well "disclose" the sentence you were too lazy to read: "Setting the style to Qt::NoPen tells the painter to not draw lines or outlines." There. How difficult was it?

rohitkk
27th June 2014, 11:58
Shame on you. I just told you to read the documentation and you keep spamming the forum without doing so; yes, that means reading the whole page. The answer to your question is right there. Had you put as much effort into solving your own problem as I have, this whole thing would have been over an hour ago.

OK, now that someone has given a major clue, I might as well "disclose" the sentence you were too lazy to read: "Setting the style to Qt::NoPen tells the painter to not draw lines or outlines." There. How difficult was it?
Chill man.
Sorry my bad I have skip the part of setting the style for the QPen.

Sorry pal.
I would definitely read the doc completely b4 posting something here.

anda_skoa
27th June 2014, 12:00
Alternatively you can use QPainter::fillRect().

Cheers,
_