How to create a window without a title, but with close / minim / maximizie buttons in QML?

I want to create an application without a title bar, but with buttons with close, minimal and maximizing. This is the purpose of the layout:

how it would look like on mac

The application is built using Go and QML. I managed to remove the headers by adding:

flags: Qt.FramelessWindowHint | Qt.Window

But this means that I need to recreate all kinds of native behavior, such as moving and resizing a window. I also recreate the close / minim / fullscreen buttons manually, but that means that I lose all kinds of behavior on the native OS, such as window binding on Windows or the zoom option on Mac.

Is there a better way to do this? Is it possible to at least create my own max-min-close buttons instead of building it in place?

thanks for all

+4
1

objective-c, . , ( .mm):

#include "macwindow.h"
#include <Cocoa.h>

MacWindow::MacWindow(long winid)
{
   NSView *nativeView = reinterpret_cast<NSView *>(winid);
   NSWindow* nativeWindow = [nativeView window];

   [nativeWindow setStyleMask:[nativeWindow styleMask] | NSFullSizeContentViewWindowMask | NSWindowTitleHidden];
   [nativeWindow setTitlebarAppearsTransparent:YES];

   [nativeWindow setMovableByWindowBackground:YES];
}

main.cpp :

#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QWindow>
#include "macwindow.h"

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

    QWindowList windows = QGuiApplication::allWindows();
    QWindow* win = windows.first();

    MacWindow* mac = new MacWindow(win->winId());

    return app.exec();
}   

.pro Cocoa:

macx:LIBS += -framework Foundation -framework Cocoa
macx:INCLUDEPATH += /System/Library/Frameworks/Foundation.framework/Versions/C/Headers \
/System/Library/Frameworks/AppKit.framework/Headers \
/System/Library/Frameworks/Cocoa.framework/Headers

, , TextEdit focus, , (my main.qml):

import QtQuick 2.5
import QtQuick.Window 2.2
import QtQuick.Controls 1.4

ApplicationWindow {
    visible: true
    color: "white"
    width: 600
    height: 400
    minimumWidth: width
    minimumHeight: height
    maximumWidth: width
    maximumHeight: height

    Rectangle {
        anchors.fill: parent
        color: "white"

        TextEdit {
            opacity: 0
            focus: true
        }
    }
}

enter image description here

+3

All Articles