Populate a QTableWidget with QTreeViews
-
Hi
Sadly the image upload is broken and we cannot see it.
Please use external site and post links here. -
@mrjj said in Populate a QTableWidget with QTreeViews:
but what else would make them windows`?
my only guess would be the
cell(0, treeViewAdresses.at(i))
is null so since the cell does not exist the widget is not added. I'm just 10% confident on this one though -
@mrjj I think the actual widget is
forest[i]
which should return a non-const ref.Anyway even
at()
will return a const reference to a non const pointer so it can take ownership as the content of the pointer is non const, just likeQWidget* const
-
@VRonin
Yeah, just thinking out loud.Well test is always the best
for (int i = 0 ; i < 10 ; ++i) { QTreeView* forest = new QTreeView(ui->tableWidget); forest->setVisible(true); ui->tableWidget->setCellWidget(i, 0, forest); }
This puts them inside
But if you change
QTreeView* forest = new QTreeView(ui->tableWidget);
-->
QTreeView* forest = new QTreeView();I get windows too.
So it was the parent !?!?!
runable test project
https://www.dropbox.com/s/8l2an24l7vp0x0l/treesintable.zip?dl=0 -
@VRonin
Hehe. And after that came the rule. If it works dont mess with it :)Well normally when reparenting a widget, all win flags are stripped so it
can be inside. Maybe in this case that part is missing?
Using a QLabel just works. -
Update:
Suddenly it works without setting parent. ( i rebooted. )If i move show() to be last, its perfect as it wont show as window for a brief moment
for (int i = 0 ; i < 10 ; ++i) { QTreeView* forest = new QTreeView(); ui->tableWidget->setCellWidget(i, 0, forest); forest->setVisible(true); }
This suddenly works.
So my other test must be flawed and the parent is not important as
setCellWidget does as we think.Meh :)
-
Hello guys. Thanks for your answerS.
The "error" was simple, stupid. In fact the_manageOrderedTable
is an instance of a class calledManageOrderedTable
which inherits from QTableWidget.
In this class, there's a method called fillAll and I calledsetColumnCount()
from there. Bad idea.
When I call this method from upon thefor
loop, everything is fine. I don't understand why.
I could understand ifsetColumnCount()
were called too late, but in this case I should have a segfault, trying to call a cell that doesn't exist.
Well, I don't really understand why but now it works...Tank you for your help, Patrick.