Qt的布局类(QLayout)-- (记录使用布局的时候出现的问题)

1.使用QLayout类的时候,出现布局无效。原因,QLayout的parent必须是继承于QFrame类,否则是无效的。
2.QGraphicsScene使用QLayout,建议将QGraphicsScene和QGraphicsView的parent设为QFrame类:示例

FrameGraphics *frame = new FrameGraphics(this); //FrameGraphics是封装的一个继承于QFrame的类
hBoxLayout->addWidget(frame);

m_view = new ViewGraphics(frame);   //ViewGraphics是封装的一个继承于QGraphicsView的类
m_view->setGeometry(0,0,this->width()/2,(this->height()-50-50));

m_scene = new SceneGraphics(frame);
qDebug()<<"width :"<<this->width();

//scene的坐标系系统比较特殊
m_scene->setSceneRect(-(m_view->width()/2),-(m_view->height()/2),m_view->width(),m_view->height());

m_view->setScene(m_scene);
m_view->show();

目前只碰到这两个比较关键的问题,后面学习中继续更新

猜你喜欢

转载自blog.csdn.net/xi__q/article/details/79799670