[[uop:draw]]
 

draw.pro

QT      += core gui widgets
CONFIG  += c++11
SOURCES += mainwindow.cc
HEADERS +=

mainwindow.cc

#include <QApplication>
#include <QPainter>
#include <QWidget>
 
class Window : public QWidget
{
public:
    Window (QWidget * parent = nullptr);
    ~Window ();
    virtual void paintEvent (QPaintEvent *event);
};
 
void Window::paintEvent (QPaintEvent * event)
{
    QPainter painter;
    painter.begin (this);
 
    int w = this->width ();
    int h = height ();
 
    painter.setPen (QColor::fromRgb (255, 0, 0));
    painter.drawLine(0, 0, w-1, 0);
 
    painter.setPen (QColor::fromRgb (0, 255, 0));
    painter.drawLine(w-1, 0, w-1, h-1);
 
    painter.setPen (QColor::fromRgb (0, 0, 255));
    painter.drawLine (w-1, h-1, 0, h-1);
 
    painter.setPen (QColor::fromRgb (255, 200, 0));
    painter.drawLine (0, h-1, 0, 0);
 
    painter.end ();
}
 
Window::Window (QWidget * parent)
   :  QWidget (parent)
{
}
 
Window::~Window ()
{
}
 
int main (int argc, char *argv[])
{
    QApplication a (argc, argv);
    Window w;
    w.show ();
    return a.exec ();
}
 
uop/draw.txt · Last modified: 2021/11/16 10:36 by 147.32.8.110
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki