Qt 6.9.2, Windows.
I put a native widget (made native with winId()) into a QTabWidget, which is a child of some root QWidget.
It works OK, but if I add more widgets, their geometry breaks.
The next widgets have regions on the right and bottom sides that are rendered with random garbage.
I have this problem on Qt 6.9.2, but the same code works fine on Qt 5.12.3.
Here's a minimal reproduction:
#include <QApplication>
#include <QPushButton>
#include <QTabWidget>
#include <QStackedWidget>
#include <QVBoxLayout>
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
auto button = new QPushButton("buton");
button->resize(200, 200);
button->show();
auto window = new QWidget{};
auto main_layout = new QVBoxLayout(window);
window->resize(500,500);
window->show();
QObject::connect(button, &QPushButton::clicked, [&]() {
auto widget = new QWidget();
widget->setStyleSheet("QWidget { background-color: #119911; }");
widget->winId(); // make it native
auto tab_widget = new QTabWidget(window);
// tab_widget->winId(); // fixes the problem
tab_widget->addTab(widget, "mytab");
main_layout->addWidget(tab_widget);
});
return QApplication::exec();
}
[image: 5e7c55d8-87fb-4b40-85c8-2eb4950b1ff0.png]
I fixed the problem by making QTabWidget native first.
I could also use Qt::WA_DontCreateNativeAncestors, but I ran into other problems with scroll areas, so I can't use this attribute.
It looks like it has something to do with the window frame. The size of the garbage area suspiciously matches the height of the window frame.
If I use the Qt::FramelessWindowHint window flag for the widget, it fixes the problem in the code above. But it doesn’t help in my actual code, where the widget hierarchy is more complicated.
I inspected the native windows of the widget and its parent with Spy++: the rectangles don't match, even though the widgets have the same geometry in GammaRay. So the native windows and Qt widgets got out of sync for some reason.
[image: 00c7eed8-a185-4560-9254-1d14e220d1e8.png]