Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-132913

Issue with Mac Window Style Implementation in Qt 6.8.0

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P1: Critical
    • None
    • 6.8.0
    • GUI: Other
    • None
    • Environment:

      macOS Sequoia 15.0.1

      Qt 6.7.3, Qt 6.8.0
    • macOS

    Description

      Environment:
      •macOS Sequoia 15.0.1
      •Qt 6.7.3 (stable) and Qt 6.8.0
       
      Description:
      In a Qt project using version 6.7.3, I successfully implemented the following functionality:
      1.Hiding the default macOS window title bar.
      2.Retaining macOS system buttons (close, minimize, zoom).
      3.Enabling drag support for the top area of the window.
       
      However, after upgrading to Qt 6.8.0 (an LTS version), the same code now results in the default macOS title bar being displayed, breaking the expected behavior.
       
      Steps to Reproduce:
      1.Use the provided code to customize the macOS window style in a Qt 6.7.3 project.
      2.Upgrade the Qt version to 6.8.0.
      3.Observe the difference in the window appearance and behavior.
       
      Expected Behavior:
      The macOS default title bar should remain hidden, and the system buttons should be displayed correctly with drag support, consistent with the behavior in Qt 6.7.3.

      Actual Behavior:
      After upgrading to Qt 6.8.0, the macOS default title bar is displayed, overriding the customizations.

      Impact:
      This issue blocks migration to Qt 6.8.0 and limits the use of its LTS benefits for projects requiring macOS window style customizations.
       
      Relevant Code:

      void MainWindow::resizeEvent(QResizeEvent *event)
      {
      LOG_INFO_VARIABLES("Enter...");
      if (event->oldSize() != event->size())
      {
      auto *mainWindow = dynamic_cast<QMainWindow *>(this->window());
      if (mainWindow && !isMinimized())
      {
      setMacWindowStyle(mainWindow);
      }
      }
      QWidget::resizeEvent(event);
      }
      
      void MainWindow::changeEvent(QEvent *event)
      {
      if (event->type() == QEvent::WindowStateChange && !isMinimized())
      {
      if (!isStyleSet)
      {
      setMacWindowStyle(this);
      isStyleSet = true;
      }
      }
      else
      {
      isStyleSet = false;
      }
      QMainWindow::changeEvent(event);
      }
      
      void MainWindow::showEvent(QShowEvent *event)
      {
      QMainWindow::showEvent(event);
      setMacWindowStyle(this); // Set the macOS window style
      }
      
      void MainWindow::setMacWindowStyle(QMainWindow *mainWindow)
      {
          QWindow *window = mainWindow->windowHandle();
          if (!window) return;
      
          NSView *nsView = reinterpret_cast<NSView *>(window->winId());
          if (nsView)
          {
              NSWindow *nsWindow = [nsView window];
              if (nsWindow)
              {
                  [nsWindow setTitleVisibility:NSWindowTitleHidden];
                  [nsWindow setTitlebarAppearsTransparent:YES];
                  [nsWindow setStyleMask:([nsWindow styleMask] | NSWindowStyleMaskFullSizeContentView)];
      
                  [[nsWindow standardWindowButton:NSWindowCloseButton] setHidden:NO];
                  [[nsWindow standardWindowButton:NSWindowMiniaturizeButton] setHidden:NO];
                  [[nsWindow standardWindowButton:NSWindowZoomButton] setHidden:NO];
      
                  DraggableView *draggableView = [[[DraggableView alloc] initWithFrame:NSMakeRect(0, 0, nsWindow.contentView.frame.size.width, 40)] autorelease];
                  [draggableView setAutoresizingMask:NSViewWidthSizable];
                  [nsWindow.contentView addSubview:draggableView positioned:NSWindowBelow relativeTo:nil];
              }
          }
      } 

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            vestbo Tor Arne Vestbø
            robert2022 Mark li
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes