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();
目前只碰到这两个比较关键的问题,后面学习中继续更新
本文解决了QLayout类使用时布局无效的问题,并提供了一种将QGraphicsScene结合QLayout的有效方法。通过实例展示了如何设置正确的parent关系来确保布局有效。
2万+

被折叠的 条评论
为什么被折叠?



