关于在QWizardPage新建页上使用QPainter的问题
各位大神,我想在QWizardPage新建页上画一些东西,提示了一个this指针的错误问题(我知道this不能随便用,但是API的例子里QPainter新建paint的时候都是用的this),看下我的代码吧,哪位大神能帮忙改下这个小错误~~谢谢了,O(∩_∩)0~~
还有如何把paint添加到页面4当中,我用layout4->addWidget(paint);也提示错误了,paint应该不是widget吧,但用什么添加到页面上呢?还是要在页面上建一个空间什么的,把图形画在上面??
刚学Qt几天,不懂的好多,大家帮帮忙哦~~
QWizardPage *createPage4(){ QWizardPage *page4 = new QWizardPage; page4->setTitle("page4"); QPainter paint( this ); //////////////错误在这里~~ QPoint pA = QPoint( 50 , 50 ) ; QPoint pB = QPoint( 50 , 550 ) ; QPoint pC = QPoint( 850 , 550 ) ; paint.drawLine( pA , pB ); paint.drawLine( pB , pC ); paint.drawText( 5 , 45, "bit/s/Hz" ); paint.drawText( 40 , 560, "O" ); paint.drawText( 830, 565, "Time(s)" );/////////////////////////////////////////画y轴坐标标度//////////////////////////// QPoint y51 = QPoint(50, 50); QPoint y52 = QPoint(55, 50); paint.drawLine(y51, y52); paint.drawText( 35 , 55, "50" ); QPoint y41 = QPoint(50, 150); QPoint y42 = QPoint(55, 150); paint.drawLine(y41, y42); paint.drawText( 35 , 155, "40" ); QPoint y31 = QPoint(50, 250); QPoint y32 = QPoint(55, 250); paint.drawLine(y31, y32); paint.drawText( 35 , 255, "30" ); QPoint y21 = QPoint(50, 350); QPoint y22 = QPoint(55, 350); paint.drawLine(y21, y22); paint.drawText( 35 , 355, "20" ); QPoint y11 = QPoint(50, 450); QPoint y12 = QPoint(55, 450); paint.drawLine(y11, y12); paint.drawText( 35 , 455, "10" );////////////////////////////////////////////////////////////////////////////////// QVBoxLayout *layout4 = new QVBoxLayout; layout4->addWidget(label4); layout4->addWidget(paint); ////////////////////错误在这里~~ page4->setLayout(layout4); return page4;}
#include <QtGui/QApplication>#include "dialog.h"#include <qwizard.h>#include <QLabel>#include <QtGui>int main(int argc, char *argv[]){ QApplication app(argc, argv); QString translatorFileName = QLatin1String("qt_"); translatorFileName += QLocale::system().name(); QTranslator *translator = new QTranslator(&app); if (translator->load(translatorFileName, QLibraryInfo::location(QLibraryInfo::TranslationsPath))) app.installTranslator(translator); QWizard wizard;// wizard.addPage(createIntroPage());// wizard.addPage(createPage1());// wizard.addPage(createPage2());// wizard.addPage(createPage3()); wizard.addPage(createPage4()); wizard.setWindowTitle("Trivial Wizard"); wizard.show(); return app.exec();}