广告
返回顶部
首页 > 资讯 > 后端开发 > 其他教程 >QT圆形图像剪切功能实现
  • 797
分享到

QT圆形图像剪切功能实现

qt图像剪切qt圆形剪切 2022-11-13 18:11:39 797人浏览 安东尼
摘要

剪切代码: Rectangle{ id:idRectRound width: 250

剪切代码:

Rectangle{
                    id:idRectRound
                    width: 250
                    height: 250
                    radius: width/2
                    anchors.centerIn: parent
                    color: "#ff00ff"
                    visible: false
                }
                Image {
                    id: idRectImg
                    width: 250
                    height: 250
                    anchors.centerIn: parent
                    source: "qrc:/res/demo.png"
                    visible: false
                    smooth: true
                }
                OpacityMask {
                    anchors.fill: idRectRound
                    source: idRectImg
                    maskSource: idRectRound
               }

完整QML源码

import QtQuick 2.12
import QtQuick.Window 2.12
import QtGraphicalEffects 1.0
 
Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("Hello World")
    color:"black"
    Rectangle{
                        id:idRectRound
                        width: 250
                        height: 250
                        radius: width/2
                        anchors.centerIn: parent
                        color: "#ff00ff"
                        visible: false
                        border.color: "yellow"
                        border.width: 2
                    }
                    Image {
                        id: idRectImg
                        anchors.centerIn: parent
                        source: "qrc:/res/demo.png"
                        visible: false
                        smooth: true
                    }
                    OpacityMask {
                        anchors.fill: idRectRound
                        source: idRectImg
                        maskSource: idRectRound
                   }
}

c++代码:

#include <QGuiApplication>
#include <QQmlApplicationEngine>
 
 
int main(int arGC, char *argv[])
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
    QGuiApplication app(argc, argv);
 
    QQmlApplicationEngine engine;
    const QUrl url(QStringLiteral("qrc:/main.qml"));
    QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                     &app, [url](QObject *obj, const QUrl &objUrl) {
        if (!obj && url == objUrl)
            QCoreApplication::exit(-1);
    }, Qt::QueuedConnection);
    engine.load(url);
 
    return app.exec();
}

到此这篇关于QT圆形图像剪切的文章就介绍到这了,更多相关qt图像剪切内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!

--结束END--

本文标题: QT圆形图像剪切功能实现

本文链接: https://www.lsjlt.com/news/169865.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作