Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-48614

QWidget::create() works fine with X11 in Qt 4.x, but does not work with Qt 5.x

XMLWordPrintable

      Many want to migrate from Qt 4.x to Qt 5.x, but at the same time users encounter a problem with QWidget::create().
      This code will work fine in Qt 4.8.4:

      MyGraphicsView::MyGraphicsView ( QWidget* parent, Qt::WindowFlags flags )
      : QWidget ( parent, flags )

      { setFocusPolicy(Qt::WheelFocus); setMouseTracking(true); setAttribute(Qt::WA_PaintOnScreen); setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_InputMethodEnabled); setMinimumSize(100,100); this->setAttribute(Qt::WA_AcceptTouchEvents); setContextMenuPolicy(Qt::PreventContextMenu); }

      void MyGraphicsView::createWindow()
      {
      .
      .
      .
      Display* display = this->x11Info().display();
      unsigned long parent = this->parentWidget()->winId();
      Window root = DefaultRootWindow(display);
      GLint att[] =

      { GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, GLX_RED_SIZE, 8, GLX_GREEN_SIZE, 8, GLX_BLUE_SIZE, 8, GLX_ALPHA_SIZE, 8, GLX_STENCIL_SIZE, 1, None }

      ;
      XVisualInfo* vi = glXChooseVisual(display, DefaultScreen(display), att);
      m_glc = glXCreateContext(display, vi, NULL, GL_TRUE);
      shareList(m_glc);
      Colormap cmap = XCreateColormap(display, root, vi->visual, AllocNone);
      XSetWindowAttributes swa;
      swa.colormap = cmap;
      swa.background_pixel = 0;
      swa.border_pixel = 0;
      unsigned long newWindow
      = XCreateWindow(display, parent, 0, 0, 600, 600,
      0, vi->depth, InputOutput, vi->visual,
      CWBackPixel|CWBorderPixel|CWColormap, &swa;
      XFree(vi);

      create(newWindow); // QWidget::create(WId window = 0, bool initializeWindow
      = true, bool destroyOldWindow = true)
      }

      However, in Qt 5.5.0 it will display nothing in graphic view canvas. And users are forced to use this approach:

      QWindow* nativewind = QWindow::fromWinId(newWindow);
      QWidget* nativewidget = QWidget::createWindowContainer(nativewind);
      nativewidget->setMouseTracking(true);
      QHBoxLayout* lo = new QHBoxLayout(this);
      lo->setContentsMargins(0,0,0,0);
      lo->addWidget(nativewidget);

      But in this case, the widgets structure is changed.

      p.s. Does this case duplicate https://bugreports.qt.io/browse/QTBUG-30786 ?

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            mmutz Marc Mutz
            kileppal Kimmo Leppälä
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes