QTreeWidget layout differs from OS to OS with same code base
-
Hi all, I have a strange problem with the QTreeWidget element order. I create the widget elements in the following way:
QTreeWidgetItem *systemData = createTreeWidgetItem(tr("System Parameters"), NO_SECTION, nullptr); systemData->addChildren(QList<QTreeWidgetItem*>() << createTreeWidgetItem(tr("Generator Data")) << createTreeWidgetItem(tr("Sensing mode")) << createTreeWidgetItem(tr("Grid options")); m_explorerLayout = createTreeWidgetItem(tr("D-VO")); m_explorerLayout->addChildren(QList<QTreeWidgetItem*>() << systemData);
On linux i get the following order (correct as you can see it reflects the order which I inserted the tems with the
addChildren
function:And on Windows I get:
What's happening here? Any clues?
-
Hi,
What OS ?
What version of Qt ?
Are you providing the translation with your application ? -
@VRonin said in QTreeWidget layout differs from OS to OS with same code base:
Can you try using
std::initializer_list
instead ofoperator <<
?
systemData->addChildren(QList<QTreeWidgetItem*>{createTreeWidgetItem(tr("Generator Data")), createTreeWidgetItem(tr("Sensing mode")), createTreeWidgetItem(tr("Grid options"))});
This seemed to do the trick. So the list initialization order is not respected with the
<<
operator? But most of all, why is it not respected only under windows?Thanks by the way.
-
@VRonin said in QTreeWidget layout differs from OS to OS with same code base:
I think it's just due to how multiple operators are resolved. The compiler you are using on windows unusually goes right to left
Thats actually important to know. Is that true for all
<<
operators ?for example QTextStream stream(&someFile); stream << "a" << "b" << "c"; actually results in "cba" on windows and "abc" on linux,in the text file ?
Or is this just for containers ?
-
@nwoki said in QTreeWidget layout differs from OS to OS with same code base:
But most of all, why is it not respected only under windows?
Which compiler is that? Can you try something for me, just for kicks?
Does this work correctly:QList<QTreeWidgetItem*> dummy; dummy << createTreeWidgetItem(tr("Generator Data")) << createTreeWidgetItem(tr("Sensing mode") << createTreeWidgetItem(tr("Grid options")); systemData->addChildren(dummy);
-
@kshegunov said in QTreeWidget layout differs from OS to OS with same code base:
@nwoki said in QTreeWidget layout differs from OS to OS with same code base:
But most of all, why is it not respected only under windows?
Which compiler is that? Can you try something for me, just for kicks?
Does this work correctly:QList<QTreeWidgetItem*> dummy; dummy << createTreeWidgetItem(tr("Generator Data")) << createTreeWidgetItem(tr("Sensing mode") << createTreeWidgetItem(tr("Grid options")); systemData->addChildren(dummy);
With your test "just for kicks", the output is inverted (see first post). I'm using the msvc2015 32bit compiler for windows
-
@nwoki said in QTreeWidget layout differs from OS to OS with same code base:
With your test "just for kicks", the output is inverted (see first post)
Did you actually run it with the dummy and not with the anonymous object is the point?
The reason I asked is I'd encountered non-compliant behavior with msvc when dealing with anonymous objects, hence the question. -
@nwoki said in QTreeWidget layout differs from OS to OS with same code base:
yup. I did as you asked
Then the compiler does not follow the rules for the C++ bitshift operators.