Details
-
Bug
-
Resolution: Cannot Reproduce
-
P2: Important
-
None
-
5.4.0, 5.5.0
-
X11
Description
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 )
void MyGraphicsView::createWindow()
{
.
.
.
Display* display = this->x11Info().display();
unsigned long parent = this->parentWidget()->winId();
Window root = DefaultRootWindow(display);
GLint att[] =
;
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 ?