简体   繁体   English

在QOpenGLWidget上添加一些QWidget

[英]Add some QWidget over a QOpenGLWidget

如何在QOpenGLWidget右下角添加QButton

The geometry property holds the geometry relative to it's parent excluding frame. geometry属性保存相对于其父级(不包括框架)的几何图形。

Calculate the position for your child widget relative to the parent widget geometry. 计算您的子小部件相对于父小部件几何的位置。

And then set the geometry using setGeometry . 然后使用setGeometry设置几何。

A rough pseudo code is below, ( Which is untested and just for Idea. The geometry calculation also may not be correct. But gives you an idea to achieve your goal ). 下面是一个粗略的伪代码( 未经测试,仅用于Idea。几何计算也可能不正确。但是可以为您实现目标提供一个思路 )。

Look into comments for details. 查看评论以获取详细信息。

//YOUR OPENGL WIDGET
QOpenGLWidget *pOpenGL =  new QOpenGLWidget(<<PARENT WINDOW>>, <<FLAGS>> );

//THE BUTTON YOU ARE TRYING TO ADD. ESTABLISH PARENT CHILD RELATION
QPushButton *pButton = new QPushButton(pOpenGL);

//THIS STEP IS IMPORTANT TO SET THE LOCATION
//CALCULATE THE GEOMETRY POSITION RELATIVE TO PARENT WIDGET 
//JUST FOR YOUR IDEA. MAY NEED TO DO SOME PROPER CALCULATIONS
pButton->setGeometry(pOpenGL->x(),pOpenGL->y()-(pOpenGL->height()-20),10,20);

//THEN SET THE CENTRAL WIDGET
setCentralWidget(pOpenGL);

You can use the function move : 您可以使用move函数:

QOpenGLWidget *openglWdg =  new QOpenGLWidget();
QPushButton  * btn = new QPushButton(openglWdg);
btn->move(0 , 0);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM