Results 1 to 17 of 17

Thread: QRect without Border

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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

Similar Threads

  1. Replies: 10
    Last Post: 9th September 2013, 15:29
  2. Replies: 2
    Last Post: 21st March 2012, 14:30
  3. QRect with border?
    By BettaUseYoNikes in forum Qt Programming
    Replies: 1
    Last Post: 24th August 2011, 00:56
  4. Marching Ant effect at the border of QRect
    By syclopse in forum Qt Programming
    Replies: 4
    Last Post: 18th April 2011, 05:28
  5. Cannot use QRect::setWidth
    By WilliamSpiderWeb in forum Newbie
    Replies: 3
    Last Post: 4th March 2011, 15: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.