您現在的位置是:網站首頁>C++QT圓形圖像剪切功能實現
QT圓形圖像剪切功能實現
宸宸2024-03-16【C++】72人已圍觀
給尋找編程代碼教程的朋友們精選了相關的編程文章,網友蔣瑞彩根據主題投稿了本篇教程內容,涉及到qt圖像剪切、qt圓形剪切、qt圖像剪切相關內容,已被314網友關注,內容中涉及的知識點可以在下方直接下載獲取。
qt圖像剪切
剪切代碼:
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#include 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圖像剪切內容請搜索碼辳之家以前的文章或繼續瀏覽下麪的相關文章希望大家以後多多支持碼辳之家!