【发布时间】:2017-03-26 05:43:19
【问题描述】:
我正在尝试在我的窗口上画一条线,但我无法实际绘制任何东西。
我的.h
#ifndef BOARD_H
#define BOARD_H
#include <Disc.h>
#include <iostream>
#include <QApplication>
#include <QPaintEvent>
class Board
{
private:
int currentDiscs;
Disc* discArray[64];
char* first;
QWidget* window;
public:
Board(int*);
int StartDrawing(QApplication*);
};
#endif
}
我的.cpp
int Board::StartDrawing(QApplication* app)
{
int WIDTH = 640;
int HEIGHT = 800;
QWidget* window = new QWidget();
window->setAttribute(Qt::WA_PaintOutsidePaintEvent, true);
window->setFixedSize(WIDTH, HEIGHT);
window->setWindowTitle("Title!");
this->window = window;
window->show();
QPainter* painter = new QPainter(window);
//QPixmap pixmap1("\\images\\tile_1.png");
//painter->drawPixmap(QPoint(0,0), pixmap1); // this works
painter->setPen(QPen(Qt::black, 12, Qt::DashDotLine, Qt::RoundCap));
painter->drawLine(10,10,100,500);
delete painter;
return app->exec();
}
我的猜测是我的 QPainter 缺少一些东西,但我没有在网上看到任何建议我需要用它调用任何其他函数的东西。
我错过了什么?
感谢您的宝贵时间。
【问题讨论】: