Qt works in the style of a seamless custom window in the style of Windows 8

I recently installed Github for Windows on my machine under Windows 7, and I liked the custom frame that it had, it fits perfectly into the general theme of the application and has its own title buttons that were really well laid out, very fluent and seemed very natural to work with .

I did a little work and found 2 flags that would completely clear the border, and after a few settings I got my application, which would also be fine-tuned and intuitive, but different from all applications with the old Windows border.

The fact is that it wasn’t easy and natural to react, like in other windows, it was damn damn, I easily got a window to move with the mouse, but it often broke down and could move around the areas that it shouldn’t like clicking and dragging on a disabled button.

The maximize button that was associated with the showMaximize method simply enlarged the entire window to cover the entire desktop, you can still move it (it has not been fully optimized).

The window did not respond to any of the system signals, such as clicking on the taskbar to minimize it, etc.

After many corrections, I just gave up, which was a shame because I really looked the way it looked, and it was very intuitive, very similar to github for Windows, very intuitive.

, , .

, Windows API XP, Windows 95, , Windows 8, Qt , .

+4
2

,

, Qt::FramelessWindowHint . , Windows , . , winapi. , , . -, Qt , . , , .

winapi Qt , . -, winapi Qt. Qt .

, winapi, , Qt . ( ) . . , Qt, , . . , Qt 4 QWidget::windowHandle " " Qt 5. , . , . ( Windows 8), :

#include "windows.h"
#include <QWindow>
//...
show();
HWND hwnd = reinterpret_cast<HWND>(effectiveWinId());
LONG lStyle = GetWindowLong(hwnd, GWL_STYLE);
lStyle &= ~(WS_CAPTION | WS_THICKFRAME | WS_MINIMIZE | WS_MAXIMIZE | WS_SYSMENU);
SetWindowLong(hwnd, GWL_STYLE, lStyle);
setWindowFlags(windowFlags() | Qt::FramelessWindowHint);
windowHandle()->reportContentOrientationChange(Qt::PrimaryOrientation);

Window Qt (. QWindowsWindow Qt). , , . Qt, . , ​​ .

, , , Windows, #ifdef Q_OS_WIN.

,

. , , .

void MainWindow::mousePressEvent(QMouseEvent *e) {
  if (!isMaximized() && 
      e->button() == Qt::LeftButton && 
      ui->title->geometry().contains(e->pos())) {
    window_drag_start_pos = e->pos();
  }
}

void MainWindow::mouseReleaseEvent(QMouseEvent *e) {
  window_drag_start_pos = QPoint(0, 0);
}

void MainWindow::mouseMoveEvent(QMouseEvent *e) {
  if (!window_drag_start_pos.isNull()) {
    move(pos() + e->pos() - window_drag_start_pos);
  }
}

void MainWindow::on_minimize_clicked() {
  showMinimized();
}

void MainWindow::on_maximize_clicked() {
  if (isMaximized()) {
    showNormal();
  } else {
    showMaximized();
  }
}

ui->title - , , QPoint window_drag_start_pos - .

+5

Qt:: FramelessWindowHint, Windows, , , .. , , , Windows Key. , Windows, Qt:: FramelessWindowHint .

- DWM API, Windows , DWM. , , , .

, Chrome, DWM (. AeroGlassFrame Chromium source). , Chrome Qt, QMainWindow Windows- , , , , :

 // Hack necessary to stop black background flicker, we cut out
 // resizeborder here to save us from having to do too much
 // addition and subtraction in Layout() ...

, Github Windows Electron, , , DWM.

DWM Qt, , , .

0

All Articles