[Solved]QDialog, Mac OS, setWindowFlags
-
i am not familiar with Mac OS platform...
-
Well, this is the only way to achieve what you want on Mac...
-
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] -
- 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
@- 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];
}
@-
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
@ -
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)));
@
- Create file called osxutil.h and paste this code to it
-
i do what u ask me to do, but nothing different happens to my dialog...awful!
-
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
@- 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];
}
@-
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
@ -
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]
- Create file osxutil.mm and paste this in it
-
The above code will not work with dialogs exec() call since it is blocking. Can you post you code here?
-
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] -
You overlooked my example :) You should call fixModalDialogClose() after show().
-
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] -
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. -
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();