我使用QT5.6显示3D帧。 我学习this example。
它运行良好,但是现在我想在此小部件中添加文本或按钮(如下图所示),并且不知道如何操作。 像this。
我试图将其添加到Window或主窗口小部件中,但失败。
Window::Window(QWindow *screen)
: QWindow(screen)
{
setSurfaceType(QSurface::OpenGLSurface);
resize(1024, 768);
QSurfaceFormat format;
if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL) {
format.setVersion(4, 3);
format.setProfile(QSurfaceFormat::CoreProfile);
}
format.setDepthBufferSize( 24 );
format.setSamples( 4 );
format.setStencilBufferSize(8);
setFormat(format);
createDisplayInfo();
create();
}
void Window::createDisplayInfo()
{
QRect geo = this->geometry();
const QString styleSheet = "background-color: rgb(0, 0, 0); color: rgb(255, 255, 255);";
QLabel *lable = new QLabel();
lable->setText("hello world:");
lable->setGeometry(10, geo.bottom() - 10 - 130, 50, 15);
lable->setStyleSheet(styleSheet);
}
失败,再尝试一个:
int main(int argc, char **argv)
{
QApplication app(argc, argv);
Window *view = new Window();
// initWidget
QWidget *container = QWidget::createWindowContainer(view);
QSize screenSize = view->screen()->size();
container->setMinimumSize(QSize(200, 100));
container->setMaximumSize(screenSize);
QWidget *widget = new QWidget;
QHBoxLayout *hLayout = new QHBoxLayout(widget);
QVBoxLayout *vLayout = new QVBoxLayout();
vLayout->setAlignment(Qt::AlignTop);
hLayout->addWidget(container, 1);
hLayout->addLayout(vLayout);
widget->setWindowTitle(QStringLiteral("Basic shapes"));
QRect geo = widget->geometry();
const QString styleSheet = "background-color: rgb(0, 0, 0); color: rgb(255, 255, 255);";
QLabel *lable = new QLabel();
lable->setText("hello world:");
lable->setGeometry(10, geo.bottom() - 10 - 130, 50, 15);
lable->setStyleSheet(styleSheet);
再次失败。
任何人都可以帮助我!