使用osgQt::QWidgetImage将Qt界面集成到OSG三维场景中

本文介绍了如何使用osgQt::QWidgetImage将Qt界面整合到OpenSceneGraph(OSG)的三维场景中,以解决OSG在界面显示上的不足。文章详细展示了创建简单Qt界面的过程,并提供了示例代码,讨论了界面的朝向和位置调整,以及信号和槽的处理。由于篇幅限制,代码仅作为参考,不能直接运行。
摘要由CSDN通过智能技术生成

写在前面

  最近在做三维gis数据显示相关的内容,开发使用的是OSG和OSGEarth,因为osg本身对界面显示这块比较弱,不能在三维场景中呈现较好的二维界面效果,所以我想的是将Qt下开发的界面集成到OSG中,王锐老师的《OpenSceneGraph3 cookbook》中有一节是专门讲这个的,算是个引子,有兴趣的同学可以先读一读这一节的内容。在实现的时候遇到了很多的问题,网上相关的资料又比较少,所以摸索了一周左右,记录一下解决过程。

正文

先写一个简单的界面类

//InfoWidget.h
#ifndef INFOWIDGET_H
#define INFOWIDGET_H

#include <QWidget>
#include <QGridLayout>
#include <QVBoxLayout>
#include <QLabel>

class InfoWidget: public QWidget
{
	Q_OBJECT
public:
	InfoWidget();
	~InfoWidget();
	void setNameValue(const QString& labelValue);
	const QString getNameValue() const;
	void setAttribute_1_Value(const QString& labelValue);
	const QString getAttribute_1_Value() const;
protected:
	void paintEvent(QPaintEvent * event);
private:
	QLabel* nameLabel;
	QLabel* nameValue;
	QLabel* attribute_1_Label;
	QLabel* attribute_1_Value;

	QGridLayout* mGridLayout;
	QVBoxLayout* mVBoxLayout;
};
#endif //INFOWIDGET_H
//InfoWidget.cpp
#include "InfoWidget.h"
#include <QPainter>

InfoWidget::InfoWidget()
{
	//文字标签
	nameLabel = new QLabel(QString::fromLocal8Bit ("姓名:"));
	nameValue = new QLabel(QString::fromLocal8Bit ("张三"));
	attribute_1_Label = new QLabel(QString::fromLocal8Bit ("性别:"));
	attribute_1_Value = new QLabel(QString::fromLocal8Bit ("男"));

	//设置标签字体,字号要尽量大一点,以便在缩放时看的清楚一点
	QFont mFont ( QString::fromLocal8Bit ("楷体"),40,75); 
	nameLabel->setFont(mFont);
	nameValue->setFont(mFont);
	attribute_1_Label->setFont(mFont);
	attribute_1_Value->setFont(mFont);
	//设置标签颜色
	QString textStyle = "color: rgb(255, 255, 51);"
	nameLabel->setStyleSheet(textStyle);
	nameValue->setStyleSheet(textStyle);
	attribut
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

鬼马行天

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值