#include "canvas.h" #include Canvas::Canvas(QWidget *parent) : QWidget{parent} , m_backgroundColor(Qt::black) { } Canvas::~Canvas() { } const QColor &Canvas::backgroundColor() const { return m_backgroundColor; } void Canvas::setBackgroundColor(const QColor &newBackgroundColor) { m_backgroundColor = newBackgroundColor; } void Canvas::paintEvent(QPaintEvent *event) { // 绘制背景颜色 QPainter painter(this); painter.fillRect(rect(), m_backgroundColor); }