QT圓形圖像剪切功能實現(xiàn)
更新時間:2022年10月21日 11:28:18 作者:江鳥木又
這篇文章主要介紹了QT圓形圖像剪切,實現(xiàn)代碼包括剪切代碼,完整QML源碼,C++代碼,代碼簡單易懂,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下

剪切代碼:
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();
}到此這篇關(guān)于QT圓形圖像剪切的文章就介紹到這了,更多相關(guān)qt圖像剪切內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
C++零基礎(chǔ)精通數(shù)據(jù)結(jié)構(gòu)之帶頭雙向循環(huán)鏈表
帶頭雙向循環(huán)鏈表:結(jié)構(gòu)最復(fù)雜,一般用在單獨存儲數(shù)據(jù)。實際中使用的鏈表數(shù)據(jù)結(jié)構(gòu),都是帶頭雙向循環(huán)鏈表。另外這個結(jié)構(gòu)雖然結(jié)構(gòu)復(fù)雜,但是使用代碼實現(xiàn)以后會發(fā)現(xiàn)結(jié)構(gòu)會帶來很多優(yōu)勢,實現(xiàn)反而簡單2022-03-03
VS報錯C6011的問題:取消對NULL指針的引用(解決方法)
這篇文章主要介紹了VS報錯C6011的問題:取消對NULL指針的引用(解決方法),C6011:取消對NULL指針的引用,發(fā)現(xiàn)是沒有進(jìn)行空指針的判斷,解決方案跟隨小編一起看看吧2024-01-01
UE4 Unlua 調(diào)用異步藍(lán)圖節(jié)點AIMoveTo函數(shù)示例詳解
這篇文章主要為大家介紹了UE4 Unlua 調(diào)用AIMoveTo函數(shù)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-09-09

