Results 1 to 17 of 17

Thread: QRect without Border

  1. #1
    Join Date
    Sep 2013
    Posts
    40
    Thanks
    6
    Thanked 3 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Post QRect without Border

    Hi All,
    Is there any way to hide/erase the border of the QRect.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QRect without Border

    Since a QRect is just a data class and has no visualization, how are you drawing the rectange?

    Cheers,
    _

  3. #3
    Join Date
    Sep 2013
    Posts
    40
    Thanks
    6
    Thanked 3 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Post Re: QRect without Border

    Quote Originally Posted by anda_skoa View Post
    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.

    Qt Code:
    1. QPrinter reportPrinter;
    2. QPainter reportPainter;
    3.  
    4. //SETTING PDF FORMAT
    5. reportPrinter.setOutputFormat(QPrinter::PdfFormat);
    6.  
    7. //DRAWING RECTANGLE ON THE PDF
    8. QRect rect = QRect(0,50,30,20);
    9. reportPainter.drawRect(rect );
    10. reportPainter.drawText(rect , Qt::AlignCenter | Qt::TextWordWrap, "SOME TEXT INSIDE");
    To copy to clipboard, switch view to plain text mode 
    I want to draw QRect rect without borders.

  4. #4
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QRect without Border

    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.

  5. #5
    Join Date
    Sep 2013
    Posts
    40
    Thanks
    6
    Thanked 3 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QRect without Border

    Quote Originally Posted by yeye_olive View Post
    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,

    Qt Code:
    1. QPen pen=reportPainter.pen();
    2. pen.setWidth(0);
    3. reportPainter.setPen(pen);
    4.  
    5. //DRAWING RECTANGLE ON THE PDF
    6. QRect rect = QRect(0,50,30,20);
    7. reportPainter.drawRect(rect );
    8. reportPainter.drawText(rect , Qt::AlignCenter | Qt::TextWordWrap, "SOME TEXT INSIDE");
    To copy to clipboard, switch view to plain text mode 

    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).

  6. #6
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QRect without Border

    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.

  7. #7
    Join Date
    Sep 2013
    Posts
    40
    Thanks
    6
    Thanked 3 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QRect without Border

    Quote Originally Posted by yeye_olive View Post
    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?

  8. #8
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QRect without Border

    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".
    Òscar Llarch i Galán

  9. #9
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QRect without Border

    Quote Originally Posted by rohitkk View Post
    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?

  10. #10
    Join Date
    Sep 2013
    Posts
    40
    Thanks
    6
    Thanked 3 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QRect without Border

    Quote Originally Posted by yeye_olive View Post
    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.

  11. #11
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QRect without Border

    Alternatively you can use QPainter::fillRect().

    Cheers,
    _

  12. #12
    Join Date
    Jan 2013
    Posts
    5
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Red face Re: QRect without Border

    Quote Originally Posted by yeye_olive View Post
    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.

  13. #13
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QRect without Border

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  14. #14
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QRect without Border

    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.

  15. #15
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QRect without Border

    Hah, you're right. I guess everyone focused on the topic of the post and didn't look closely enough at the code.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  16. #16
    Join Date
    Jan 2013
    Posts
    5
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QRect without Border

    Quote Originally Posted by d_stranz View Post
    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.

  17. #17
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QRect without Border

    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.
    Last edited by d_stranz; 8th November 2020 at 23:06.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 10
    Last Post: 9th September 2013, 16:29
  2. Replies: 2
    Last Post: 21st March 2012, 15:30
  3. QRect with border?
    By BettaUseYoNikes in forum Qt Programming
    Replies: 1
    Last Post: 24th August 2011, 01:56
  4. Marching Ant effect at the border of QRect
    By syclopse in forum Qt Programming
    Replies: 4
    Last Post: 18th April 2011, 06:28
  5. Cannot use QRect::setWidth
    By WilliamSpiderWeb in forum Newbie
    Replies: 3
    Last Post: 4th March 2011, 16:45

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.