QWidget.show导致界面卡住
很奇怪的问题,定义了一个QWidget,显示背景图片,但是每当加载图片的时候,转动的图标就会卡住,但是删除show方法则不会卡住,而且当我使用resize()函数调整界面分辨率时发现图标实际上还是动的。
求大侠解读。。谢谢
代码如下:
graphwidgt::graphwidgt(QWidget *parent) : QGraphicsView(parent), m_pageOffset(0), top(1), bottom(2), row(1), col(0), left(0), right(0){ num = 0; //解决中文乱码问题 QTextCodec *codec = QTextCodec::codecForName("GB2312"); QTextCodec::setCodecForLocale(codec); QTextCodec::setCodecForCStrings(codec); QTextCodec::setCodecForTr(codec);#if 0 connect(&m_pageAnimator, SIGNAL(frameChanged(int)), SLOT(shiftPage(int))); m_pageAnimator.setDuration(600); m_pageAnimator.setFrameRange(0, 1000); m_pageAnimator.setCurveShape(QTimeLine::LinearCurve); m_pageAnimator.setUpdateInterval(5);#endif m_pChildView = NULL; QGraphicsScene *m_scene = new QGraphicsScene(this); //原点在中心点 m_scene->setSceneRect(sceneCenterX, sceneCenterY, 320, 240); //不使用index作为item搜索,index适用于静态scene m_scene->setItemIndexMethod(QGraphicsScene::NoIndex); /* 将元素背景图片添加到列表中 */ QList<QPixmap> pixmaps; QDirIterator it(":/", QStringList() << "*.png"); while (it.hasNext() && pixmaps.size() < mouseCount) { pixmaps << it.next(); } m_pWidget = new QGraphicsWidget(); m_group = new QGraphicsItemGroup(m_pWidget); /******************/ int i = 100; int num = 0; /* 添加menu元素 */ for (int j = 0; j < rowCounts; j++) { //QGraphicsItemGroup *group = m_scene->createItemGroup(m_scene->selectedItems()); for (int k = 0; k < colCounts; k++) { num++; QPixmap pixmap(pixmaps.at(num % pixmaps.size())); //pixmap = pixmap.scaledToWidth(200); QZteLabel *item = new QZteLabel(this); item->setPixmap(pixmap); m_scene->addItem(item); item->setPos(200 * k + 100, 50 + 230 * j); //item->setZValue(1); m_positions[j] << QPointF(item->QGraphicsPixmapItem::pos().x(), item->QGraphicsPixmapItem::pos().y()); m_items[j] << item; m_group->addToGroup(item); } //m_group.append(group); }// m_scene->addItem(m_group); m_scene->addItem(m_pWidget); setScene(m_scene); //view.centerOn((sceneCenterX + sceneWidth) / 2, (sceneCenterY + sceneHeight) / 2); //渲染提示,Antialiasing使得边缘平滑,效果非常好,QPainter是低层次的绘图// setRenderHint(QPainter::Antialiasing); //代替默认背景 //setBackgroundBrush(QPixmap(":/background/background.png")); //setStyleSheet("background:transparent"); setAttribute(Qt::WA_TranslucentBackground, true); setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); //setWindowFlags(Qt::WType_TopLevel|Qt::WStyle_StaysOnTop); setCacheMode(QGraphicsView::CacheBackground); //刷新模式,矩形刷新 setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate); //view.setDragMode(QGraphicsView::ScrollHandDrag); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setAlignment(Qt::AlignLeft | Qt::AlignTop); //QT_TRANSLATE_NOOP固定标题,中文乱码问题 setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "Colliding Mice 老鼠")); //QList<>remove有问题 //view.items().removeAt(0); //resize有可能导致无穷递归 resize(viewWidth, viewHight); QRectF boundingRect = m_items[0][1]->boundingRect(); on_actionZoom_Widget_triggered();#if 0 m_Timer.setInterval(100); connect(&m_Timer, SIGNAL(timeout()), this, SLOT(slideUp())); m_Timer.start(3000);#endif}