Qt功能优化:Qt 3D画廊

简介: Qt功能优化:Qt 3D画廊

Qt功能优化:Qt 3D画廊

一、效果图

如下图所示:
在这里插入图片描述

二、使用步骤

1. .pro部分

代码如下:
TEMPLATE = app

QT += qml quick
CONFIG += c++11

SOURCES += main.cpp

RESOURCES += qml.qrc \
    image.qrc


# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =

# Additional import path used to resolve QML modules just for Qt Quick Designer
QML_DESIGNER_IMPORT_PATH =

# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

2. .qml部分

Demo.qml

代码如下:
import QtQuick 2.0
import QtGraphicalEffects 1.0

Rectangle {
    id:coverflow

    property ListModel model
    property int itemCount: 5

    PathView{
        id:pathView
        model:coverflow.model
        delegate: Item {
            id:delegateItem
            width: 530
            height: 420
            z:PathView.iconZ
            scale:PathView.iconScale

            Image{
                id:image
                source: url
                width: delegateItem.width
                height: delegateItem.height
            }
            ShaderEffect {
                anchors.top: image.bottom
                width: image.width
                height: image.height;
                anchors.left: image.left
                property variant source: image;
                property size sourceSize: Qt.size(0.5 / image.width, 0.5 / image.height);
                fragmentShader:
                        "varying highp vec2 qt_TexCoord0;
                        uniform lowp sampler2D source;
                        uniform lowp vec2 sourceSize;
                        uniform lowp float qt_Opacity;
                        void main() {

                            lowp vec2 tc = qt_TexCoord0 * vec2(1, -1) + vec2(0, 1);
                            lowp vec4 col = 0.25 * (texture2D(source, tc + sourceSize) + texture2D(source, tc- sourceSize)
                            + texture2D(source, tc + sourceSize * vec2(1, -1))
                            + texture2D(source, tc + sourceSize * vec2(-1, 1)));
                            gl_FragColor = col * qt_Opacity * (1.0 - qt_TexCoord0.y) * 0.2;
                        }"
            }



            transform: Rotation{
                origin.x:image.width/2.0
                origin.y:image.height/2.0
                axis{x:0;y:1;z:0}
                angle: delegateItem.PathView.iconAngle
            }
        }
        path:coverFlowPath
        pathItemCount: coverflow.itemCount
        anchors.fill: parent

        preferredHighlightBegin: 0.5
        preferredHighlightEnd: 0.5

    }

    Path{
        id:coverFlowPath
        startX: 0
        startY: coverflow.height/3

        PathAttribute{name:"iconZ";value: 0}
        PathAttribute{name:"iconAngle";value: 70}
        PathAttribute{name:"iconScale";value: 0.6}
        PathLine{x:coverflow.width/2;y:coverflow.height/3}

        PathAttribute{name:"iconZ";value: 100}
        PathAttribute{name:"iconAngle";value: 0}
        PathAttribute{name:"iconScale";value: 1.0}

        PathLine{x:coverflow.width;y:coverflow.height/3}
        PathAttribute{name:"iconZ";value: 0}
        PathAttribute{name:"iconAngle";value: -70}
        PathAttribute{name:"iconScale";value: 0.6}
        PathPercent{value:1.0}

    }

}


main.qml

代码如下:
import QtQuick 2.8
import QtQuick.Window 2.2

Window {
    visible: true
    width:1800
    height: 880
    title: qsTr("灵眸")


    ListModel{
        id:model
        ListElement{url:"qrc:/image/1.png"}
        ListElement{url:"qrc:/image/2.png"}
        ListElement{url:"qrc:/image/3.png"}
        ListElement{url:"qrc:/image/4.png"}
        ListElement{url:"qrc:/image/6.png"}
        ListElement{url:"qrc:/image/7.png"}
        ListElement{url:"qrc:/image/8.png"}
        ListElement{url:"qrc:/image/9.png"}
        ListElement{url:"qrc:/image/10.png"}
        ListElement{url:"qrc:/image/11.png"}
        ListElement{url:"qrc:/image/12.png"}
        ListElement{url:"qrc:/image/13.png"}
        ListElement{url:"qrc:/image/14.png"}

    }

    CoverFlow{
        anchors.fill:parent
        model:model
    }


}

3. .cpp部分

main.cpp

代码如下:
#include <QGuiApplication>
#include <QQmlApplicationEngine>

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    if (engine.rootObjects().isEmpty())
        return -1;

    return app.exec();
}

    

总结

以上是部分Qt关于功能优化——Qt功能优化:Qt 3D画廊的完整版代码部分,另附Qt功能优化:Qt 3D画廊完整素材和代码压缩包,用户也可直接关注微信公众号:云曦智划,回复“3D画廊”,即可免费获取。同时,所有相关的Qt界面优化的部分,均在下方专栏——Qt功能优化中,大家如果感兴趣可以进行观看并使用,希望通过这些文章能够使大家的Qt软件更加美观和完美 !!!

另,如果大家有时间的话,也可以在个人主页中的专栏部分,查看我的Qt实战专栏Qt界面优化专栏哦,里面分别存放有Qt相关的实战软件和相对实用的附属功能,大家感兴趣可以看看(๑>؂<๑)

另附Qt实战:云曦聊天室篇Qt界面优化:鼠标双击特效两篇相关文章,大家可以下滑到文章下方专栏处,查看相关专栏中的其它文章,希望能帮助到大家,感谢大家支持~( ̄▽ ̄~)~

相关文章
|
28天前
|
开发框架 Java 编译器
【Qt 元对象系统 01 】深入探索Qt的元对象系统:核心地位、功能与构成
【Qt 元对象系统 01 】深入探索Qt的元对象系统:核心地位、功能与构成
50 0
|
1月前
|
数据可视化 API vr&ar
探索Qt 3D之旅:从基础到实战,打造引人入胜的三维界面与应用
探索Qt 3D之旅:从基础到实战,打造引人入胜的三维界面与应用
110 2
|
3月前
QT4.7版本的OPENGL的3D旋转模型例子
QT4.7版本的OPENGL的3D旋转模型例子
|
6月前
|
Linux API Windows
linux系统中利用QT实现蓝牙功能的方法
linux系统中利用QT实现蓝牙功能的方法
228 0
|
6月前
|
Linux
linux系统中利用QT实现音乐播放器的功能
linux系统中利用QT实现音乐播放器的功能
95 0
|
7月前
|
算法 C++
|
6月前
|
Ubuntu Linux API
linux系统中使用QT实现摄像头功能的方法
linux系统中使用QT实现摄像头功能的方法
106 0
|
6月前
|
存储 Linux
linux系统中使用QT实现多媒体的功能方法
linux系统中使用QT实现多媒体的功能方法
72 0
|
8月前
|
存储
QT+OpenGL开始3D
顶点坐标起始于局部空间,它在之后会变为世界坐标,观察坐标,裁减坐标,并最后以屏幕坐标的形式结束。
55 0