Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 3

Qt-interest Archive, June 2007
Painting rectangles with border


Message 1 in thread

Hi,

Qt currently paints a rectangle by painting the area of the rectangle with
the brush and then painting the border with the pen on top of it as the
following program shows:

#include <QtGui>
#include <QtDebug>


int main(int argc, char ** argv) {
   QApplication app(argc, argv);

   QRect r(10, 10, 100, 100);
   QPixmap pix(200, 200);
   pix.fill(Qt::transparent);   
   
   {
      QPainter p(&pix);
      
      QPen pen(QColor(255, 0, 0, 128));
      pen.setWidth(10);
      pen.setMiterLimit(50);
      pen.setJoinStyle(Qt::MiterJoin);
      
      p.setPen(pen);
      p.setBrush(QBrush(Qt::blue));
      
      p.drawRect(r);
   
   }
   QLabel label;
   label.setPixmap(pix);
   label.show();
   app.exec();
}

One sees that the border overlaps the inner rectangle in the resulting
picture.

But is this what one expects? I expect that the border is painted with the
pen and the unpainted inner rest is drawn with the brush.

Could anyone give me a hint to the documentation where it states that
rectangles are drawn in the current way and not as I expect it?

Christoph

--
 [ signature omitted ] 

Message 2 in thread

Christoph Bartoschek wrote:
> Hi,
> 
> Qt currently paints a rectangle by painting the area of the rectangle with
> the brush and then painting the border with the pen on top of it as the
> following program shows:
...

> One sees that the border overlaps the inner rectangle in the resulting
> picture.
> 
> But is this what one expects? I expect that the border is painted with the
> pen and the unpainted inner rest is drawn with the brush.
> 
> Could anyone give me a hint to the documentation where it states that
> rectangles are drawn in the current way and not as I expect it?

http://doc.trolltech.com/4.3/coordsys.html

--
 [ signature omitted ] 

Message 3 in thread

Gunnar Sletta wrote:

> http://doc.trolltech.com/4.3/coordsys.html

Hi,

this page does not state that the border of a rectangle and the filled area
overlap.

There is only a discussion about how the coordinates of a border match to
the pixels of the canvas.

Or am I missing a paragraph?

Christoph

--
 [ signature omitted ] 

Message 4 in thread

look at the example picture for QRect(1, 2, 6, 4):

it shows how the border (filled with a light green) and the actual
rectangle that is filled with the brush (hatched with darker horizontal
lines) overlap.

Cheers,
Peter

> -----Original Message-----
> From: Christoph Bartoschek [mailto:bartoschek@xxxxxx]
> Sent: Monday, June 11, 2007 5:34 PM
> To: qt-interest@xxxxxxxxxxxxx
> Subject: Re: Painting rectangles with border
> 
> Gunnar Sletta wrote:
> 
> > http://doc.trolltech.com/4.3/coordsys.html
> 
> Hi,
> 
> this page does not state that the border of a rectangle and the filled
> area
> overlap.
> 
> There is only a discussion about how the coordinates of a border match
to
> the pixels of the canvas.
> 
> Or am I missing a paragraph?
> 
> Christoph
> 
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/

--
 [ signature omitted ] 

Message 5 in thread

Peter Prade wrote:

> look at the example picture for QRect(1, 2, 6, 4):
> 
> it shows how the border (filled with a light green) and the actual
> rectangle that is filled with the brush (hatched with darker horizontal
> lines) overlap.

Ok, thanks. I have to learn to draw rectangles in two steps from now on.

Christoph

--
 [ signature omitted ]