首页 > 其他分享 >qt圆形图像剪切

qt圆形图像剪切

时间:2022-10-22 15:37:03浏览次数:76  
标签:idRectRound qt visible width 图像 false 250 剪切 anchors


qt圆形图像剪切_#include

 剪切代码:

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();
}

标签:idRectRound,qt,visible,width,图像,false,250,剪切,anchors
From: https://blog.51cto.com/remotedev/5785881

相关文章

  • Photoshop 2023 (ps 2023) for Mac/Win(图像处理必备软件)支持M1最新版
    ps作为一款电脑必备修图工具,受到广大网友的推崇,目前,该版本已经更新到ps2023版!最新的ps2023帮助你组合、修饰和重新混合您的照片,为您的旧黑白添加新颜色,或者让不需要的东......
  • 基于遗传算法的二进制图像重建附Matlab代码
    ✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。......
  • Qt从文件中读取配置
    #ifndefWIDGET_H#defineWIDGET_H#include<QWidget>#include<QString>QT_BEGIN_NAMESPACEnamespaceUi{classWidget;}QT_END_NAMESPACEclassWidget:publicQWidge......
  • QT槽函数
    #ifndefWIDGET_H#defineWIDGET_H#include<QWidget>QT_BEGIN_NAMESPACEnamespaceUi{classWidget;}QT_END_NAMESPACEclassWidget:publicQWidget{Q_OBJECTpubl......
  • Qt 5.15.2 QTextEdit无法设置新字体的处理方式
    首发于我的个人博客:xie-kang.com博客内有更多文章,欢迎大家访问原文地址在使用QT5.15.2开发的过程中碰到了件怪事,下列代码无法给QTextEdit选中的文字设置字体:QTextCur......
  • Qt Windows上实现毛玻璃效果
    首发于我的个人博客:xie-kang.com博客内有更多文章,欢迎大家访问原文地址前言:很多人看到这个需求的第一想法都是录制软件窗口后的桌面内容,并且加上个高斯模糊就能实现了......
  • 想到一种用json描述Qt弹性布局的方式
    规则:列表第一项描述 QHBox or QVBox 第二项描述是否可拉伸,也就是QBox or QSplitter列表可嵌套 渲染:deffun(self,ui):ifui[0]=="H":......
  • SpringBoot集成MQTT的步骤和注意事项
    最近项目用到了mqtt,所以记录下SpringBoot集成MQTT的步骤和注意事项,整理一下知识,方便自己和他人。一、pom文件里引入maven依赖jar包<dependency><groupId>org.sprin......
  • 学习和思考:思考的形式——声音和图像
    思考的形式——声音和图像    思考是一种心理活动。我用“声音”演绎“内心活动(心理活动)”;即用“声音”表演“内心戏”。这就是用“声音”进行“思考”,就是用......
  • Linux 下 Qt Creator 的安装,并使用它开发你的第一个 Qt 项目全过程
    Linux下QtCreator的安装使用       Qt以其开源,免费,完全面向对象(很容易扩展),允许真正的组件编程以及可移植跨平台等诸多优势得到越来越多的开发人员的青睐。QtC......