Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Replacing QMacCocoaViewContainer with QWidget::createWindowContainer().

Replacing QMacCocoaViewContainer with QWidget::createWindowContainer().

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 4 Posters 1.2k Views 4 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.
  • Jonas KvingeJ Offline
    Jonas KvingeJ Offline
    Jonas Kvinge
    wrote on last edited by
    #1

    Hi guys. I'm trying to replace QMacCocoaViewContainer with QWidget::createWindowContainer().

    The code is:

    static inline void setupLayout(NSView *cocoaView, QWidget *parent) {
    parent->setAttribute(Qt::WA_NativeWindow);
    QVBoxLayout *layout = new QVBoxLayout(parent);
    layout->setMargin(0);
    layout->addWidget(new QMacCocoaViewContainer(cocoaView, parent));
    }

    I've tried QWidget::createWindowContainer(QWindow::fromWinId(parent->winId()), parent);

    The code is here: https://github.com/strawberrymusicplayer/strawberry/blob/master/src/widgets/qocoa_mac.h
    This is just a helper function that is used in qsearchfield_mac.mm. The class is QSearchField that was written by Mike McQuaid, the class is different for macOS, written in objective C using Qocoa to have a native macOS look.

    1 Reply Last reply
    1
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What is happening ?
      What is the issue ?
      Which version Of Qt ?
      Which version of macOS ?

      And out of curiosity, why do you want to switch ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • Jonas KvingeJ Offline
        Jonas KvingeJ Offline
        Jonas Kvinge
        wrote on last edited by
        #3

        I had to look into the source code of QMacCocoaViewContainer to find the answer here.

        The solution is: QWidget::createWindowContainer(QWindow::fromWinId(WId(cocoaView))
        Where cocoaView is the NSView.

        (6 questions to a simple question like this is very unhelpful, if you knew how to help with it you would have known the answer by looking at the code I shared).

        1 Reply Last reply
        1
        • artwawA Offline
          artwawA Offline
          artwaw
          wrote on last edited by artwaw
          #4

          Posting a piece of code without sufficient context (working environment, version of the software) and then being rude if someone asks is also unhelpful.

          Things change both in Qt and in the system, it is often hard to give correct answer without knowing the above.

          For more information please re-read.

          Kind Regards,
          Artur

          1 Reply Last reply
          2
          • V Offline
            V Offline
            Violet Giraffe
            wrote on last edited by Violet Giraffe
            #5

            This was, in fact, very helpful - I came here looking for how to replace QMacCocoaViewContainer which is no longer available in Qt 6.
            Or is there a way to bring it back in Qt 6.2?

            P. S. The method described here works in Qt 5.15 and 6.2, tested on macOS 11.6 and 12.0 The only downside is you can't inherit from the native widget, i. e. make it an instance of your subclass.

            1 Reply Last reply
            1

            • Login

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