n3squik
n3squik

Reputation: 165

draw an image on a widget with Qt

I'm discovering Qt and I'm stuck on a very simple problem: I try to draw an image on a widget.

I have no issue at drawing some Pies or Rectangles, but I see nothing for the image...

Here is the part of may code:

void GraphicWidget::paintEvent(QPaintEvent * /* event */)
{
QPainter painter(this);
painter.setPen(Qt::red);
painter.setBrush(Qt::blue);
painter.translate(0, rect().height());

QPixmap pixmap;
if ( pixmap.load("Lena.png") )
{
     std::cout << "succes" << std::endl;
     painter.drawPixmap( QPoint(100,100), pixmap );
}
else
     std::cout << "fail" << std::endl;

    painter.drawPie(QRect(-35, -35, 70, 70), 0, 90 * 16);//works
    painter.drawRect(QRect(30, -5, 20, 10));            //works
}

Upvotes: 2

Views: 10884

Answers (1)

Pavel Strakhov
Pavel Strakhov

Reputation: 40492

You have translated the coordination system of QPainter. So your x should be in [0, width] interval and your y should be in [-height, 0] interval. QPoint(100,100) is out of your widget's borders.

Upvotes: 2

Related Questions