This commit is contained in:
thepra 2017-08-28 10:07:22 +02:00
parent e03bda56ea
commit 7ff3b29476
6 changed files with 211 additions and 10 deletions

View File

@ -25,10 +25,12 @@ DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += \
main.cpp \
mainwindow.cpp
mainwindow.cpp \
renderarea.cpp
HEADERS += \
mainwindow.h
mainwindow.h \
renderarea.h
FORMS += \
mainwindow.ui

View File

@ -1,5 +1,6 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPainter>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
@ -12,3 +13,9 @@ MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::paintEvent(QPaintEvent* event)
{
QPainter painter{this};
painter.setBrush(QColor{26,25,25});
}

View File

@ -15,6 +15,9 @@ class MainWindow : public QMainWindow
explicit MainWindow(QWidget *parent = root);
~MainWindow();
protected:
void paintEvent(QPaintEvent* event) Q_DECL_OVERRIDE;
private:
constexpr static QWidget* root = 0;
Ui::MainWindow *ui;

View File

@ -10,27 +10,159 @@
<height>600</height>
</rect>
</property>
<property name="palette">
<palette>
<active>
<colorrole role="Button">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>26</red>
<green>25</green>
<blue>25</blue>
</color>
</brush>
</colorrole>
<colorrole role="Light">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>26</red>
<green>26</green>
<blue>26</blue>
</color>
</brush>
</colorrole>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>26</red>
<green>25</green>
<blue>25</blue>
</color>
</brush>
</colorrole>
<colorrole role="Window">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>26</red>
<green>25</green>
<blue>25</blue>
</color>
</brush>
</colorrole>
</active>
<inactive>
<colorrole role="Button">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>26</red>
<green>25</green>
<blue>25</blue>
</color>
</brush>
</colorrole>
<colorrole role="Light">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>26</red>
<green>26</green>
<blue>26</blue>
</color>
</brush>
</colorrole>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>26</red>
<green>25</green>
<blue>25</blue>
</color>
</brush>
</colorrole>
<colorrole role="Window">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>26</red>
<green>25</green>
<blue>25</blue>
</color>
</brush>
</colorrole>
</inactive>
<disabled>
<colorrole role="Button">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>26</red>
<green>25</green>
<blue>25</blue>
</color>
</brush>
</colorrole>
<colorrole role="Light">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>26</red>
<green>26</green>
<blue>26</blue>
</color>
</brush>
</colorrole>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>26</red>
<green>25</green>
<blue>25</blue>
</color>
</brush>
</colorrole>
<colorrole role="Window">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>26</red>
<green>25</green>
<blue>25</blue>
</color>
</brush>
</colorrole>
</disabled>
</palette>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(26, 25, 25);</string>
</property>
<widget class="QWidget" name="centralWidget">
<widget class="QPushButton" name="pushButton">
<property name="styleSheet">
<string notr="true">background-color: rgb(26, 25, 25);</string>
</property>
<widget class="RenderArea" name="renderArea" native="true">
<property name="geometry">
<rect>
<x>120</x>
<y>140</y>
<width>80</width>
<height>21</height>
<x>10</x>
<y>10</y>
<width>571</width>
<height>531</height>
</rect>
</property>
<property name="text">
<string>PushButton</string>
</property>
</widget>
</widget>
<widget class="QStatusBar" name="statusBar"/>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>RenderArea</class>
<extends>QWidget</extends>
<header>renderarea.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

31
renderarea.cpp Normal file
View File

@ -0,0 +1,31 @@
#include "renderarea.h"
#include <QPainter>
RenderArea::RenderArea(QWidget *parent) :
QWidget{parent},
mBackgroundColour{36,35,35},
mShapeColour{251,250,250}
{
}
QSize RenderArea::minimumSizeHint() const
{
return QSize(100,100);
}
QSize RenderArea::sizeHint() const
{
return QSize(400,200);
}
void RenderArea::paintEvent(QPaintEvent* event)
{
QPainter painter{this};
painter.setBrush(mBackgroundColour);
painter.setRenderHint(QPainter::Antialiasing,true);
painter.setPen(mShapeColour);
painter.drawRect(this->rect());
painter.drawLine(this->rect().topLeft(),this->rect().bottomRight());
}

26
renderarea.h Normal file
View File

@ -0,0 +1,26 @@
#ifndef RENDERAREA_H
#define RENDERAREA_H
#include <QWidget>
class RenderArea : public QWidget
{
Q_OBJECT
public:
explicit RenderArea(QWidget *parent = nullptr);
QSize minimumSizeHint() const Q_DECL_OVERRIDE;
QSize sizeHint() const Q_DECL_OVERRIDE;
signals:
protected:
void paintEvent(QPaintEvent* event) Q_DECL_OVERRIDE;
public slots:
private:
QColor mBackgroundColour;
QColor mShapeColour;
};
#endif // RENDERAREA_H