2014-04-05 77 views
1

我已經通過使用qt/qml完成了無框窗口,但是現在我無法使用win7窗口鏈接器(向左和向右)添加窗口並將其拖到屏幕的頂部。有什麼辦法來處理這些信號?無框pyqt/qml窗口

main.py

class MainDialog(QtQuick.QQuickView): 
def __init__(self, parent = None): 
    super(MainDialog, self).__init__(parent) 

    self.maxed = False 

    self.ctx = self.engine().rootContext() 
    self.ctx.setContextProperty("view", self) 
    self.ctx.setContextProperty("maximized", self.maxed) 

    self.setSource(QtCore.QUrl("Main.qml")) 
    self.setResizeMode(QtQuick.QQuickView.SizeRootObjectToView) 

    self.setFlags(QtCore.Qt.FramelessWindowHint 
     | QtCore.Qt.Window 
     | QtCore.Qt.WindowSystemMenuHint 

    ) 
    self.setColor(QtGui.QColor(QtCore.Qt.transparent)) 

    self.engine().quit.connect(App.quit) 

main.qml

import QtQuick 2.1 

Rectangle { 
id: main 

width: 500 
height: 600 

visible: true 
border.color: "black" 

opacity: .95 
    MouseArea { 
     anchors.fill: frame 

     onPressed: { 
      frame.mouse_x = mouseX 
      frame.mouse_y = mouseY 
     } 

     onPositionChanged: { 
      view.x += mouse.x - frame.mouse_x 
      view.y += mouse.y - frame.mouse_y 
     } 

     onDoubleClicked: !maximized ? view.set_max() 
      : view.set_normal() 
    } 
} 

回答

2

如果你的主窗口沒有裝飾物,則該用戶不能將任何事情所以不能移動或調整窗口。

對於移動窗口,您可以提供一個窗口小部件來移動窗口,最簡單的情況是處理該窗口小部件上的鼠標點擊事件,將窗口轉換爲「移動」,在這種情況下,窗口的鼠標移動處理程序根據窗口的位置老鼠。在發佈時,轉換回「不移動」。或者,您可以將您的應用程序背景上的鼠標點擊解釋爲「窗口拖動」,然後您將派生並處理鼠標事件以移動窗口。

要調整大小,您必須在窗口中創建一些用戶可以拖動來調整大小的項目(除非您想使用滾輪,但不遵循標準界面設計)。點擊該項目後,您將再次處理鼠標事件,並將其解釋爲「窗口大小調整」。