首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > QT开发 >

请问大牛。场景中添加视图Graphicsview 视图内的控件为何闪烁

2012-12-26 
请教大牛。。。场景中添加视图Graphicsview视图内的控件为何闪烁?示例代码如下:新建工程放入Mainwindow构造Ma

请教大牛。。。场景中添加视图Graphicsview 视图内的控件为何闪烁?
示例代码如下:新建工程放入Mainwindow构造
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent)
{
    resize(1000,500);
    /////////////////////////////////////////////////////////////////////body
    QGraphicsView *pBody = new QGraphicsView(this);

    QGraphicsScene *pSBody = new QGraphicsScene();

    pSBody->setSceneRect(0,0,800,400);
    pBody->setScene(pSBody);
    pBody->setGeometry(QRect(100,50,800,400));

    pBody->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    pBody->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    //无边框设置
    pBody->setFrameShape(QFrame::NoFrame);

    //设置背景透明
    pBody->setBackgroundRole(QPalette::Background);
    pBody->setPalette(QPalette(QColor(255,0,0,0)));

    pBody->setStyleSheet(QString("QGraphicsView{background-color:#66cc33;}"));
//////////////////////////////////////////////////////

    QGraphicsProxyWidget *pDivProxy = new QGraphicsProxyWidget();
    pDivProxy->setParent(pBody);

    QGraphicsView *pDiv = new QGraphicsView();

    QGraphicsScene *pSDiv = new QGraphicsScene();

    pSDiv->setSceneRect(0,0,600,200);
    pDiv->setScene(pSDiv);
    pDiv->resize(600,200);
    pDiv->setGeometry(QRect(100,100,600,200));
    pDiv->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    pDiv->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    pDiv->setStyleSheet(QString("QGraphicsView{background-color:#22ccFF;}"));


    //pDiv->setParent(pBody);
    pDiv->setObjectName("div");
    pDivProxy->setWidget(pDiv);
    pDivProxy->setGeometry(QRect(100,100,600,200));


    QGraphicsProxyWidget *pNumProxy = new QGraphicsProxyWidget();
    QGraphicsProxyWidget *pPowProxy = new QGraphicsProxyWidget();
    QGraphicsProxyWidget *pSumProxy = new QGraphicsProxyWidget();


    QLineEdit *pNum = new QLineEdit();
    QLineEdit *pPow = new QLineEdit();
    QLineEdit *pSum = new QLineEdit();

    pNumProxy->setWidget(pNum);
    pPowProxy->setWidget(pPow);
    pSumProxy->setWidget(pSum);


    pNumProxy->setGeometry(QRect(20,20,100,30));
    pPowProxy->setGeometry(QRect(20,60,100,30));
    pSumProxy->setGeometry(QRect(150,60,80,60));

    pNumProxy->setParent(pDivProxy);
    pPowProxy->setParent(pDivProxy);
    pSumProxy->setParent(pDivProxy);
////////////////////////////////////////////////////////////////////////////////////
    QGraphicsProxyWidget *pDivProxy1 = new QGraphicsProxyWidget();


    pDivProxy1->setParent(pDivProxy);

    QGraphicsView *pDiv1 = new QGraphicsView();

    QGraphicsScene *pSDiv1 = new QGraphicsScene();

    pSDiv1->setSceneRect(0,0,600,200);
    pDiv1->setScene(pSDiv1);
    pDiv1->resize(600,200);
    pDiv1->setGeometry(QRect(300,0,600,200));
    pDiv1->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    pDiv1->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    pDiv1->setStyleSheet(QString("QGraphicsView{background-color:#FFcc11;}"));

    pDivProxy1->setWidget(pDiv1);
    pDivProxy1->setGeometry(QRect(300,0,600,200));

    QGraphicsProxyWidget *pNumProxy1 = new QGraphicsProxyWidget();
    QGraphicsProxyWidget *pPowProxy1 = new QGraphicsProxyWidget();
    QGraphicsProxyWidget *pSumProxy1 = new QGraphicsProxyWidget();

    QLineEdit *pNum1 = new QLineEdit();
    QLineEdit *pPow1 = new QLineEdit();
    QLineEdit *pSum1 = new QLineEdit();

    pNumProxy1->setWidget(pNum1);
    pPowProxy1->setWidget(pPow1);
    pSumProxy1->setWidget(pSum1);


    pNumProxy1->setGeometry(QRect(20,20,100,30));
    pPowProxy1->setGeometry(QRect(20,60,100,30));
    pSumProxy1->setGeometry(QRect(150,60,80,60));

    pNumProxy1->setParent(pDivProxy1);
    pPowProxy1->setParent(pDivProxy1);
    pSumProxy1->setParent(pDivProxy1);

    pSDiv1->addItem(pNumProxy1);
    pSDiv1->addItem(pPowProxy1);
    pSDiv1->addItem(pSumProxy1);
////////////////////////////////////////////////////////////////////////////////////
    pSBody->addItem(pDivProxy);

    pSDiv->addItem(pNumProxy);
    pSDiv->addItem(pPowProxy);
    pSDiv->addItem(pSumProxy);
    pSDiv->addItem(pDivProxy1);

}
[最优解释]
这写的太乱了  QGraphicsScene 用一个就行了 用几个view进行显示就可以了,你这都没布局,item位置都没有,显示的时候是顺序把你添加的组件都显示了一遍 看起来就是闪烁了
[其他解释]
我的目的是把view添加到场景里,而view又有自己绑定的场景   这样形成层次,嵌套的关系   你说的Item我用proxywidget进行了相关布局,不知道你是否把代码运行过。。。还请多多指教

热点排行