本文介绍了如何制作“真正的透明"窗口到光标,最好在纯 QML 上?(Qt 5.7)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

真正的透明度"说明(图片,76kb).

在该图像上 ApplicationWindow 有一个视觉透明层.但实际上,光标并没有跑到ApplicationWindow后面的窗口(这里是QT Creator).

On that image ApplicationWindow have a visually transparent layer. But in fact, cursor does not go to the window behind ApplicationWindow (in this case - QT Creator).

如果添加(取消注释)Qt.WindowTransparentForInput"标志,则实现真正透明",但按钮不再可用(这很明显,我知道).

"True Transparency" is achieved if add (uncomment) "Qt.WindowTransparentForInput" flag, but the buttons are no longer available (it's are obvious, I know).

我尝试了具有相似含义的各种标志(来自文档),但没有找到有效的组合 - 光标在窗口边界内时停留在默认"状态(必须处于文本"状态,因为那是它下面的文字).

I have tried a various flags with similar meanings (from the documentation), but did not find a working combination - cursor are stayind in "default" state when it is within borders of the window (must be in "text" state, because that are text below it).

是否有人遇到过类似的问题,您是否找到了解决方案?谢谢!

Did somebody faced with a similar problem, and are you find a solution? Thanks!

来自图像的代码,其他项目文件保持不变(Qt Quick Controls 2 应用程序):

Code from image, other project files stayed untouched (Qt Quick Controls 2 Application):

import QtQuick 2.7
import QtQuick.Controls 1.5

ApplicationWindow {
    visible: true
    width: 320
    height: 240
    x: 400
    y: 210
    color: "transparent"
    flags: Qt.Widget | Qt.FramelessWindowHint //| Qt.WindowTransparentForInput
    //| Qt.WA_TranslucentBackground //| Qt.WA_NoSystemBackground
    //| Qt.WA_NoBackground //| Qt.WA_MouseNoMask

    Button {
        x: ApplicationWindow.width - width
        text: "Right Top Window Corner"
    }
    Button {
        y: ApplicationWindow.height - height
        text: "Left Bottom Window Corner"
    }
}

推荐答案

一种解决方案是创建 3 个窗口,一个用于透明区域,一个用于每个按钮.

One solution is to create a 3 windows, one for the transparent area and one for each of the buttons.

import QtQuick 2.4
import QtQuick.Controls 1.5
import QtQuick.Window 2.0

ApplicationWindow {
    id: app
    visible: true
    width: 320
    height: 240
    x: 400
    y: 210
    color: "transparent"
    flags: Qt.Widget | Qt.FramelessWindowHint | Qt.WindowTransparentForInput | Qt.WindowStaysOnTopHint

    Window {
        visible: true
        flags: Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint
        x: app.width - width
        height: rightButton.implicitHeight
        Button {
            id: rightButton
            text: "Right Top Window Corner"
        }
    }
    Window {
        visible: true
        flags: Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint
        y: app.height - height
        height: leftButton.implicitHeight
        Button {
            id: leftButton
            text: "Left Bottom Window Corner"
        }
    }
}

这篇关于如何制作“真正的透明"窗口到光标,最好在纯 QML 上?(Qt 5.7)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 13:52