Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved]QDialog, Mac OS, setWindowFlags
Qt 6.12 LTS is out! See what's new in the release blog

[Solved]QDialog, Mac OS, setWindowFlags

Scheduled Pinned Locked Moved General and Desktop
17 Posts 4 Posters 13.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    toptan
    wrote on last edited by
    #7

    Well, this is the only way to achieve what you want on Mac...

    1 Reply Last reply
    0
    • G Offline
      G Offline
      gaojinhsu
      wrote on last edited by
      #8

      Could you tell me more about where I should call your function and how to "include" osxutil.mm ?
      [quote author="toptan" date="1368515186"]Well, this is the only way to achieve what you want on Mac...[/quote]

      1 Reply Last reply
      0
      • T Offline
        T Offline
        toptan
        wrote on last edited by
        #9
        1. Create file called osxutil.h and paste this code to it
          @
          #ifndef UTIL_H
          #define UTIL_H

        #include <QDialog>

        void fixModalDialogClose(QDialog *dialog, bool resizable);

        #endif // UTIL_H
        @

        1. Create file osxutil.mm and paste this in it
          @
          #import <AppKit/NSView.h>
          #import <AppKit/NSWindow.h>

        #include "util.h"

        void fixModalDialogClose(QDialog *dialog, bool resizable)
        {
        NSView *view = (NSView *)dialog->winId();
        NSWindow *window = [view window];
        if (resizable)
        [window setStyleMask:NSClosableWindowMask | NSTitledWindowMask | NSResizableWindowMask];
        else
        [window setStyleMask:NSClosableWindowMask | NSTitledWindowMask];
        }
        @

        1. Open the project file (.pro) and add util.h into HEADERS and osxutil.mm into OBJECTIVE_SOURCES. Something like
          @
          HEADERS += util.h
          OBJECTIVE_SOURCES += osutil.mm
          @

        2. Here is the small example how I use fixModalDialogClose
          @
          m_aboutDialog = new MyAboutDialog();
          m_aboutDialog->show();
          fixModalDialogClose(m_aboutDialog, false);
          connect(m_aboutDialog, SIGNAL(finished(int)), this, SLOT(onAboutDialogFinished(int)));
          @

        1 Reply Last reply
        0
        • G Offline
          G Offline
          gaojinhsu
          wrote on last edited by
          #10

          i do what u ask me to do, but nothing different happens to my dialog...awful!

          1 Reply Last reply
          0
          • G Offline
            G Offline
            gaojinhsu
            wrote on last edited by
            #11

            i do what u ask me to do, but nothing different happens to my dialog…awful!
            [quote author="toptan" date="1368516008"]1. Create file called osxutil.h and paste this code to it
            @
            #ifndef UTIL_H
            #define UTIL_H

            #include <QDialog>

            void fixModalDialogClose(QDialog *dialog, bool resizable);

            #endif // UTIL_H
            @

            1. Create file osxutil.mm and paste this in it
              @
              #import <AppKit/NSView.h>
              #import <AppKit/NSWindow.h>

            #include "util.h"

            void fixModalDialogClose(QDialog *dialog, bool resizable)
            {
            NSView *view = (NSView *)dialog->winId();
            NSWindow *window = [view window];
            if (resizable)
            [window setStyleMask:NSClosableWindowMask | NSTitledWindowMask | NSResizableWindowMask];
            else
            [window setStyleMask:NSClosableWindowMask | NSTitledWindowMask];
            }
            @

            1. Open the project file (.pro) and add util.h into HEADERS and osxutil.mm into OBJECTIVE_SOURCES. Something like
              @
              HEADERS += util.h
              OBJECTIVE_SOURCES += osutil.mm
              @

            2. Here is the small example how I use fixModalDialogClose
              @
              m_aboutDialog = new MyAboutDialog();
              m_aboutDialog->show();
              fixModalDialogClose(m_aboutDialog, false);
              connect(m_aboutDialog, SIGNAL(finished(int)), this, SLOT(onAboutDialogFinished(int)));
              @

            [/quote]

            1 Reply Last reply
            0
            • T Offline
              T Offline
              toptan
              wrote on last edited by
              #12

              The above code will not work with dialogs exec() call since it is blocking. Can you post you code here?

              1 Reply Last reply
              0
              • G Offline
                G Offline
                gaojinhsu
                wrote on last edited by
                #13

                main.cpp:
                @#include "accessdlg.h"
                #include "osxutil.h"

                int main(int argc, char *argv[])
                {
                QApplication a(argc, argv);
                AccessDlg accDlg(true);
                fixModalDialogClose(&accDlg, false);
                accDlg.show();
                return a.exec();
                }
                @
                osxutil.h:
                @
                #ifndef UTIL_H
                #define UTIL_H

                #include <QDialog>

                void fixModalDialogClose(QDialog *dialog, bool resizable);

                #endif // UTIL_H
                @
                osxutil.mm:
                @#import <AppKit/NSView.h>
                #import <AppKit/NSWindow.h>

                #include "osxutil.h"

                void fixModalDialogClose(QDialog *dialog, bool resizable)
                {
                NSView view = (NSView)dialog->winId();
                NSWindow *window = [view window];
                if(resizable)
                [window setStyleMask:NSClosableWindowMask | NSTitledWindowMask | NSResizableWindowMask];
                else
                [window setStyleMask:NSClosableWindowMask | NSTitledWindowMask];
                }
                @
                .pro file:
                @OBJECTIVE_SOURCES += osxutil.mm
                HEADERS += osxutil.h
                @
                [quote author="toptan" date="1368522370"]The above code will not work with dialogs exec() call since it is blocking. Can you post you code here?[/quote]

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  toptan
                  wrote on last edited by
                  #14

                  You overlooked my example :) You should call fixModalDialogClose() after show().

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    gaojinhsu
                    wrote on last edited by
                    #15

                    Bingo! btw,can i remove the other two disabled buttons?
                    [quote author="toptan" date="1368523275"]You overlooked my example :) You should call fixModalDialogClose() after show().[/quote]

                    1 Reply Last reply
                    0
                    • T Offline
                      T Offline
                      toptan
                      wrote on last edited by
                      #16

                      I guess you could. Look at Apple's documentation for NSWindow and play with setStyleMask in fixModalDialogClose method.
                      Please mark thread as solved by editing first post and prepending [SOLVED] to thread subject.

                      1 Reply Last reply
                      0
                      • napajejenunedk0N Offline
                        napajejenunedk0N Offline
                        napajejenunedk0
                        wrote on last edited by
                        #17

                        bq. The above code will not work with dialogs exec() call since it is blocking. Can you post you code here?

                        It works. But you need to call both show() and exec():

                        QDialog dlg;
                        dlg.show();
                        fixModalDialogClose( & dlg, false );
                        dlg.exec();

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt
                        • Unsolved