简体   繁体   中英

Add some QWidget over a QOpenGLWidget

如何在QOpenGLWidget右下角添加QButton

The geometry property holds the geometry relative to it's parent excluding frame.

Calculate the position for your child widget relative to the parent widget geometry.

And then set the geometry using 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 ).

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 :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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