PDA

View Full Version : QRect without Border



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

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

Cheers,
_

rohitkk
27th June 2014, 09: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, 09: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, 10: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, 10: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, 10: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, 10: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, 10: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, 10: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, 11:00
Alternatively you can use QPainter::fillRect().

Cheers,
_

markanth
8th October 2020, 23:55
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?

I'm not sure I understand the motivation for all the negativity here. Sure, reading the fine manual can be a very helpful thing. However, leveraging Google to immediately find a solution to a problem can be much faster. As a result of this fine person having asked the question, I found my answer more quickly.

d_stranz
9th October 2020, 19:23
I found my answer more quickly.

And it only took you 6 1/3 years after this was posted in June 2014. Fast work. Good for you. ;)

ChrisW67
10th October 2020, 05:23
Seems to me the OP's original complaint was that calling drawRect() drew a rectangle. There was no specific request or attempt to draw a filled rectangle, so the quickest way to fix the "problem" was to not call drawRect().
Quite surprised that nobody picked that up at the time.

d_stranz
10th October 2020, 18:46
Hah, you're right. I guess everyone focused on the topic of the post and didn't look closely enough at the code.

markanth
7th November 2020, 04:29
And it only took you 6 1/3 years after this was posted in June 2014. Fast work. Good for you. ;)

I think you missed the point Kemo Sahbee, Google found this link for me instantly. My point is that search engines are better at indexing than are manuals--especially for specific questions.

d_stranz
8th November 2020, 22:02
True. I've spent much of the weekend on Google trying to understand why I can no longer connect to my NAS server from Windows 10. But sometimes Google remembers too much. Posts dating from Windows NT days aren't helpful.