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. NSView embed in QWidget covers other sibling widgets, why?
Qt 6.11 is out! See what's new in the release blog

NSView embed in QWidget covers other sibling widgets, why?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 574 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.
  • P Offline
    P Offline
    pengxu
    wrote on last edited by
    #1
    int main(int argc, char *argv[])
    {    
        QApplication a(argc, argv);
        
        QWidget* mw = new QWidget();
        mw->setFixedSize(800, 600);    
        
        QWidget* canvas = new QWidget(mw);
        canvas->setGeometry(0, 0, 800, 600);
        canvas->setStyleSheet("background-color:red");
    
        NSView* remote = [[NSView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
        [remote setWantsLayer:true];
        remote.layer.backgroundColor = [NSColor yellowColor].CGColor;
        NSView* cv = reinterpret_cast<NSView*>(canvas->winId());
        [cv addSubview:remote];
        [remote setTranslatesAutoresizingMaskIntoConstraints:NO];
        [remote.bottomAnchor constraintEqualToAnchor:cv.bottomAnchor constant:0.0f].active = YES;
        [remote.leadingAnchor constraintEqualToAnchor:cv.leadingAnchor constant:50.0f].active = YES;
        [remote.widthAnchor constraintEqualToAnchor:cv.widthAnchor multiplier:1.0f constant:0.0f].active = YES;
        [remote.heightAnchor constraintEqualToAnchor:cv.heightAnchor multiplier:1.0f constant:0.0f].active = YES;
     
        
        QWidget* tool = new QWidget(mw);
        tool->setGeometry(0, 400, 800, 600);
        tool->setStyleSheet("background-color:green");
        
        mw->show();
        return a.exec();
    }
    
    

    屏幕快照 2021-10-28 下午4.37.17.png

    why the yellow remote nsview (which is in the red canvas) alwas covers the green tool widget (which is on top of red canvas)

    mac os 10.13.6

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

      Hi,

      Which version of Qt are you using ?

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

      P 2 Replies Last reply
      0
      • P Offline
        P Offline
        pengxu
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          Which version of Qt are you using ?

          P Offline
          P Offline
          pengxu
          wrote on last edited by
          #4

          @SGaist
          5.14.2, I also tried 5.15.2, but still the same on mac os 10.13

          1 Reply Last reply
          0
          • SGaistS SGaist

            Hi,

            Which version of Qt are you using ?

            P Offline
            P Offline
            pengxu
            wrote on last edited by
            #5

            @SGaist can you help me? Thanks very much!

            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 Extensions
            • Unsolved