여기 내 코드입니다 : 다음과 같이 qmake를 -project 후하나의 cpp 파일에서만 QPainter를 어떻게 사용합니까?
#include<QApplication>
#include<QWidget>
#include<QPaintEvent>
#include<QPainter>
int main(int argc,char**argv)
{
QApplication app(argc,argv);
QWidget*wid=new QWidget;
wid->setWindowTitle("sb");
QPainter paint;
paint.setWindow(0,0,900,900);
QRectF border(3*45-20,25,670,850);
QRectF inter(3*45,45,630,810);
paint.setPen(Qt::NoPen);
paint.setBrush(QBrush(Qt::darkMagenta,Qt::SolidPattern));
paint.drawRect(border);
paint.setBrush(QBrush(Qt::gray,Qt::SolidPattern));
paint.drawRect(inter);//
paint.setPen(QPen(Qt::darkGray,3,Qt::SolidLine,Qt::RoundCap,Qt::RoundJoin));
paint.setPen(Qt::NoPen);
paint.beginNativePainting();
wid->show();
return app.exec();
}
, qmake를 만들, 그것은 잘못 : 음
[email protected]:~/QTproj/t1$ ./t1
QPainter::setWindow: Painter not active
QPainter::setPen: Painter not active
QPainter::setBrush: Painter not active
QPainter::drawRects: Painter not active
QPainter::setBrush: Painter not active
QPainter::drawRects: Painter not active
QPainter::setPen: Painter not active
QPainter::setPen: Painter not active
QPainter::beginNativePainting: Painter not active
~~ 방법합니다 (QPainter가 하나 개의 CPP 파일에 활성 내가 paint.h, paint.cpp 및 main.cpp 같은 별도의 파일을 사용하고 싶지 않아요. 내가 QWidget을 상속 클래스를 만드는 경우 작동하도록 만들 수 있지만, 그것을 작동하게하는 방법을 시도하고 싶습니다. 하나의 파일) ?? 덕분에 많은 ~ ;-)
QWidget에 페인트를 적용하려면 서브 클래스를 만들어서 paintEvent를 재정의해야합니다. –