Qt笔记-Q3DScatter及QCustom3DItem的基本使用
生活随笔
收集整理的這篇文章主要介紹了
Qt笔记-Q3DScatter及QCustom3DItem的基本使用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
這里加載了obj文件。程序運行截圖如下:
感覺還不錯,Qt自己封裝了OpenGL,Qt開發者只需要依靠邏輯進行調用即可。
?
關鍵代碼如下:
using namespace QtDataVisualization;Widget::Widget(QWidget *parent) :QWidget(parent),ui(new Ui::Widget) {ui->setupUi(this);this->setWindowTitle("CSDN IT1995");Q3DScatter *graph = new Q3DScatter();QWidget *container = QWidget::createWindowContainer(graph);if (!graph->hasContext()) {QMessageBox msgBox;msgBox.setText("Couldn't initialize the OpenGL context.");msgBox.exec();return;}//添加數據QCustom3DItem *item = new QCustom3DItem();item->setScaling(QVector3D(0.03f, 0.03f, 0.03f));item->setMeshFile(":/img/oo.obj");qDebug() << "The ret is : " << graph->addCustomItem(item);//設置到控件上QHBoxLayout *hLayout = new QHBoxLayout();hLayout->addWidget(container, 1);ui->widget->setLayout(hLayout); }這里主要邏輯是,先使用QtDataVisualization命名空間。
首先構造一個Q3Dcatter,隨后將其套個套子,這個套子名為QWidget。
再把Q3Dcatter中添加QCustom3DItem,構建obj模型文件。
最后把這個套子加入布局中,布局再放到可拖拽的界面中。
?
源碼下載地址:
https://github.com/fengfanchen/Qt/tree/master/3DScatter%20Demo
?
總結
以上是生活随笔為你收集整理的Qt笔记-Q3DScatter及QCustom3DItem的基本使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Redis工作笔记-spring整合je
- 下一篇: Qt文档阅读笔记-QNetworkAcc