为什么没有执行paintevent这个函数?

weixin_38062043 2019-09-19 03:05:04
#include "mainwindow.h"#define cout qDebug() test :: test(QMainWindow *parent) : QMainWindow(parent){     setGeometry(320,320,320,320);     mywidget = new QWidget;    mywidget->setGeometry(320,320,320,320);    setCentralWidget(mywidget);     newaction = new QAction(tr("New Game"),this);    connect(newaction,SIGNAL(triggered()),this,SLOT(newdraw()));     aboutaction = new QAction(tr("About"),this);    connect(aboutaction,SIGNAL(triggered()),this,SLOT(about()));     filemenu = menuBar()->addMenu(tr("File"));    filemenu->addSeparator();    filemenu -> addAction(newaction);     aboutmenu = menuBar()->addMenu(tr("About"));    aboutmenu->addSeparator();    aboutmenu->addAction(aboutaction);    Test = new QPushButton(tr("aa"),this);    connect(Test,SIGNAL(clicked()),this,SLOT(newdraw()));    Test->setGeometry(32,32,32,32);     isdraw = false;    memset(arrmap,0,sizeof(arrmap));    photolist.clear();    for(int i = 1 ; i <= 5; i++)    {        QString phname = ":/image/"+QString::number(i,10)+".gif";        QPixmap pixmap(phname);        photolist.append(pixmap);    }} void test:: newdraw(){    isdraw =  true;    update();} void test :: paintevent(QPaintEvent */*event*/){    cout << "@@@@@@@@@@@@@@@@@";// 没有运行    if(!isdraw) return;    QPainter painter(this);    for(int i = 1; i <= 8; i++)    {        for(int j = 1 ; j <= 8; j++)        {            arrmap[j] = rand() % 5;        }    }    for(int i = 1; i <= 8; i ++)    {        for(int j =1; j <= 8; j++)        {            painter.drawPixmap((j-1)*(32),(i-1)*(32),32,32,photolist.at(arrmap[j]));        }    }    painter.drawEllipse(32,32,32,32);    update();}
...全文
37 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复

476

社区成员

发帖
与我相关
我的任务
社区描述
其他技术讨论专区
其他 技术论坛(原bbs)
社区管理员
  • 其他技术讨论专区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧