[Qt-interest] Drawing rectangular

Stephen Jackson spjackson42 at gmail.com
Mon Sep 21 10:33:15 CEST 2009


On Mon, Sep 21, 2009 at 8:38 AM, Yuvaraj R wrote:
> No
>
> I used simple lines
>
> QPainter paint(this)
>
> paint.DrawRect(100,100,100,100);
>
>
> what's with this code?
>

Given the *right context*, there's nothing whatsoever wrong with the above code.

Below is a minimum compilable example that demonstrates a rectangle
being drawn with precisely the above code.

#include <QtGui>

class MyWidget : public QWidget
{
protected:
    virtual void paintEvent(QPaintEvent *);
};

void MyWidget::paintEvent(QPaintEvent * e)
{
    QPainter paint(this);
    paint.drawRect(100,100,100,100);
}

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

    MyWidget *widget = new MyWidget();
    widget->show();

    return app.exec();
}

-- 
HTH,

Stephen Jackson



More information about the Qt-interest-old mailing list