Question

I've done frameless window by using qt/qml, but now i can't use win7 window linkers(to the right and left coners) and maximize window by draging it to the top of the screen. Is there any way to handle those signals?

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()
    }
}
Was it helpful?

Solution

If your main window does not have decorations, then the user cannot drag anything so can't move or resize window.

For moving window, you could provide a widget to move window, simplest case is handle mouse click event on that widget transitions the window to "moving", in this case the window's mouse move handler moves the window according to location of mouse. On release, transition back to "non-moving". Alternately, you could interpret a mouse click on background of your app as a "window drag" then you would derive and handle mouse events to move window.

To resize, you'll have to create some item in your window that user can drag to resize (unless you want to use scrollwheel but that would not follow standard interface design). You would again handle mouse events when that item is clicked and interpret them as "window resize".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top