c++ - my window product key
क्यूटी क्विक के साथ पारदर्शी विंडो कैसे बनाएं? (3)
क्या एक qml अनुप्रयोग की खिड़की पारदर्शी बनाने का कोई तरीका है?
मैं एप्लिकेशन की खिड़की को पारदर्शी, साथ ही साथ पृष्ठभूमि बनाते समय qml के साथ सरल आकार को आकर्षित करने के बारे में एक विस्तृत विवरण की तलाश में हूं। एक कामकाजी स्रोत कोड डेमो भयानक होगा।
कम से कम क्यूटी 5.3 के रूप में आपको पिछले उत्तरों की तरह विस्तृत जानकारी की आवश्यकता नहीं है:
Window {
flags: Qt.ToolTip | Qt.FramelessWindowHint | Qt.WA_TranslucentBackground
color: "#00000000"
काम हो गया। (आप टूलटिप को बदलना चाहेंगे। मैं इसका उपयोग कर रहा हूं क्योंकि मैं टूलटिप्स बना रहा हूं।)
खिड़की पारदर्शी छोड़ते समय मुझे अंततः लाल / नीले आयताकारों को आकर्षित करने का एक आसान तरीका मिला।
draw_rectangles.qml
import Qt 4.7
Item {
Rectangle {
opacity: 0.5
color: "red"
width: 100; height: 100
Rectangle {
color: "blue"
x: 50; y: 50; width: 100; height: 100
}
}
}
win.cpp :
#include <QApplication>
#include <QDeclarativeView>
#include <QMainWindow>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QMainWindow window;
QDeclarativeView* v = new QDeclarativeView;
window.setCentralWidget(v);
v->setSource(QUrl::fromLocalFile(("draw_rectangles.qml")));
window.setStyleSheet("background:transparent;");
window.setAttribute(Qt::WA_TranslucentBackground);
window.setWindowFlags(Qt::FramelessWindowHint);
window.show();
return app.exec();
}
win.pro :
TEMPLATE += app
QT += gui declarative
SOURCES += win.cpp
इन फ़ाइलों को एक ही निर्देशिका में सहेजें और एप्लिकेशन को संकलित करने के बाद qmake
निष्पादित करें।
ये रहा एक सरल उदाहरण:
main.cpp :
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
mainwindow.h :
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QDeclarativeView>
class MainWindow : public QDeclarativeView
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
};
#endif // MAINWINDOW_H
mainwindow.cpp :
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QDeclarativeView(parent)
{
// transparent background
setAttribute(Qt::WA_TranslucentBackground);
setStyleSheet("background:transparent;");
// no window decorations
setWindowFlags(Qt::FramelessWindowHint);
// set QML file
setSource(QUrl("main.qml"));
}
MainWindow::~MainWindow()
{
}
main.qml
import QtQuick 1.0
Rectangle {
id: root
width: 250
height: 250
// completely transparent background
color: "#00FFFFFF"
border.color: "#F00"
border.width: 2
Rectangle {
id: ball
height: 50; width: 50
x: 100
color: "#990000FF"
radius: height / 2
}
SequentialAnimation {
running: true; loops: Animation.Infinite
NumberAnimation { target: ball; property: "y"; to: root.height - ball.height; duration: 1000; easing.type: Easing.OutBounce }
PauseAnimation { duration: 1000 }
NumberAnimation { target: ball; property: "y"; to: 0; duration: 700 }
PauseAnimation { duration: 1000 }
}
}
transp-qml.pro
QT += core gui declarative
TARGET = transp-qml
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
OTHER_FILES += main.qml
परिणाम का स्क्रीनशॉट: