stdware / qwindowkit

Cross-platform frameless window framework for Qt. Support Windows, macOS, Linux.
Apache License 2.0
599 stars 94 forks source link

qml 启用 frameless 后,双击 titlebar 不能最大化窗口 #95

Open hanxipu opened 5 months ago

hanxipu commented 5 months ago

set(QWINDOWKIT_ENABLE_QT_WINDOW_CONTEXT ON CACHE BOOL "") set(QWINDOWKIT_ENABLE_WINDOWS_SYSTEM_BORDERS OFF CACHE BOOL "")

CMakelists.txt

set(QWINDOWKIT_BUILD_STATIC ON CACHE BOOL "")
set(QWINDOWKIT_BUILD_WIDGETS OFF CACHE BOOL "")
set(QWINDOWKIT_BUILD_QUICK ON CACHE BOOL "")
set(QWINDOWKIT_ENABLE_QT_WINDOW_CONTEXT ON CACHE BOOL "")
set(QWINDOWKIT_ENABLE_WINDOWS_SYSTEM_BORDERS OFF CACHE BOOL "")

# Add subdirectories
add_subdirectory(qwindowkit)

# Set project source files
set(PROJECT_SOURCES
    main.cpp
    qml/main.qml
    qml/QWKButton.qml
    qml/qml.qrc
    resources/qwk.qrc
)

# Add executable based on Qt version
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
  qt_add_executable(${PROJECT_NAME}
    MANUAL_FINALIZATION
    ${PROJECT_SOURCES}
  )
else()
  add_executable(${PROJECT_NAME}
    ${PROJECT_SOURCES}
  )
endif()

# Configure target
qm_configure_target(${PROJECT_NAME}
    QT_LINKS Core Gui Qml Quick
    LINKS QWKQuick
)

main.qml

    WindowAgent {
        id: windowAgent
    }

    MouseArea {
        anchors.fill: parent
        acceptedButtons: Qt.LeftButton

        onDoubleClicked: {
            if (window.visibility === Window.Maximized) {
                window.showNormal()
            } else {
                window.showMaximized()
            }
        }
    }

这个双击事件只在 icon 上产生效果,其他位置不生效

hanxipu commented 5 months ago

现在是注释掉

        // Component.onCompleted: windowAgent.setTitleBar(titleBar)

然后自己实现来解决这个问题

wangwenx190 commented 5 months ago

你给的main.qml代码片段太短,就几行,我们怎么分析?

一定要仔细看README。被设置为标题栏的item,所有交互事件都会被接管,也就是不再会响应任何鼠标事件了。如果你想让标题栏内的控件继续响应鼠标事件,要手动setHitTestVisible。