aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/qtmacnativewidget/main.mm9
-rw-r--r--src/qtmacnativewidget.h12
-rw-r--r--src/qtmacnativewidget.mm13
3 files changed, 24 insertions, 10 deletions
diff --git a/examples/qtmacnativewidget/main.mm b/examples/qtmacnativewidget/main.mm
index c40518a..927eb73 100644
--- a/examples/qtmacnativewidget/main.mm
+++ b/examples/qtmacnativewidget/main.mm
@@ -39,7 +39,14 @@
**
****************************************************************************/
-#include <QtWidgets>
+#include <QApplication>
+#include <QDebug>
+#include <QHBoxLayout>
+#include <QLineEdit>
+#include <QPainter>
+#include <QPushButton>
+#include <QVBoxLayout>
+#include <QWidget>
#include <Cocoa/Cocoa.h>
#include <qtmacnativewidget.h>
diff --git a/src/qtmacnativewidget.h b/src/qtmacnativewidget.h
index 78c453e..e6684de 100644
--- a/src/qtmacnativewidget.h
+++ b/src/qtmacnativewidget.h
@@ -41,7 +41,7 @@
#ifndef QTMACNATIVEWIDGET_H
#define QTMACNATIVEWIDGET_H
-#include <QtWidgets/QWidget>
+#include <QWidget>
#import <Availability.h>
QT_BEGIN_HEADER
@@ -52,24 +52,18 @@ QT_MODULE(Gui)
#ifdef __OBJC__
@class NSView;
+#else
+typedef struct objc_object NSView;
#endif
class QtMacNativeWidget : public QWidget
{
Q_OBJECT
public:
-#ifdef __OBJC__
QtMacNativeWidget(NSView *parentView = 0);
-#else
- QtMacNativeWidget(void *parentView = 0);
-#endif
~QtMacNativeWidget();
-#ifdef __OBJC__
NSView *nativeView() const;
-#else
- void *nativeView() const;
-#endif
QSize sizeHint() const;
protected:
diff --git a/src/qtmacnativewidget.mm b/src/qtmacnativewidget.mm
index 83add40..8249d60 100644
--- a/src/qtmacnativewidget.mm
+++ b/src/qtmacnativewidget.mm
@@ -40,9 +40,11 @@
****************************************************************************/
#include "qtmacnativewidget.h"
+#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
#include <QtGui/QWindow>
#include <QtGui/QGuiApplication>
#include <qpa/qplatformnativeinterface.h>
+#endif
#include <qdebug.h>
#import <Cocoa/Cocoa.h>
@@ -67,6 +69,7 @@
QT_BEGIN_NAMESPACE
+#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
NSView *getEmbeddableView(QWindow *qtWindow)
{
// Set Qt::SubWindow flag. Should be done before crate() is
@@ -83,6 +86,7 @@ NSView *getEmbeddableView(QWindow *qtWindow)
NSView *qtView = (NSView *)platformNativeInterface->nativeResourceForWindow("nsview", qtWindow);
return qtView; // qtView is ready for use.
}
+#endif
/*!
Create a QtMacNativeWidget with \a parentView as its "superview" (i.e.,
@@ -101,8 +105,12 @@ QtMacNativeWidget::QtMacNativeWidget(NSView *parentView)
NSView *QtMacNativeWidget::nativeView() const
{
+#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
winId();
return getEmbeddableView(windowHandle());
+#else
+ return reinterpret_cast<NSView*>(winId());
+#endif
}
/*!
@@ -119,9 +127,14 @@ QSize QtMacNativeWidget::sizeHint() const
{
// QtMacNativeWidget really does not have any other choice
// than to fill its designated area.
+#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
if (windowHandle())
return windowHandle()->size();
return QWidget::sizeHint();
+#else
+ NSRect frame = [nativeView() frame];
+ return QSize(frame.size.width, frame.size.height);
+#endif
}
/*!
\reimp