PDA

View Full Version : QTreeView branch images won't show up



nuliknol
24th January 2015, 19:01
Hi,
I am trying to setup a tree visualization like in this picture (with "+" and "-" signs):
http://qt.developpez.com/doc/4.6/images/simpletreemodel-example.png
but I only see the default setup with triangles.
I have checked the stylesheet reference , downloaded and put the vline.png and branch-more.png from the internet and put it into the build directory , also just in case copied to source directory, and also added as resource. But the images won't show up.
The code to set the stylesheet of the QTreeView is this:



deptree=new QTreeWidget();
deptree->setColumnCount(2);
deptree->setStyleSheet("QTreeView::branch:has-siblings:!adjoins-item { border-image: url(:/images/deptrack_images/vline.png) 0; }");
deptree->setStyleSheet("QTreeView::branch:has-siblings:adjoins-item { border-image: url(:/images/deptrack_images/branch-more.png) 0;}");
deptree->setStyleSheet("QTreeView::branch:!has-children:!has-siblings:adjoins-item { border-image: url(branch-end.png) 0;}");
deptree->setStyleSheet("QTreeView::branch:has-children:!has-siblings:closed,");
deptree->setStyleSheet("QTreeView::branch:closed:has-children:has-siblings { border-image: none; image: url(notexistentfile.png); }");
deptree->setStyleSheet("QTreeView::branch:open:has-children:!has-siblings,");
deptree->setStyleSheet("QTreeView::branch:open:has-children:has-siblings { border-image: none; image: url(branch-open.png); }");

twi=new QTreeWidgetItem();
twi->setText(0,"uno");
deptree->addTopLevelItem(twi);
ptwi=twi;

twi=new QTreeWidgetItem();
twi->setText(0,"subuno");
ptwi->addChild(twi);

ptwi=twi;
twi=new QTreeWidgetItem();
twi->setText(0,"subsubuno");
ptwi->addChild(twi);

main_layout->addWidget(deptree);
tree_test->setLayout(main_layout);
tree_test->show();


I think the problem is: QT can't locate the images. How do I know , if the image is opened successfuly by the stylesheet? I have ran the debugger with "Step In" to setStyleSheet() method but it doesn't do anything there, that would look like opening an image, it even doesn't get close to stylesheet code. I also have put wrong image file names on purpose, and it is absolutely ignored, the triangles keep appearing as nothing hapened.

Is there any example of a table I am trying to do online so I could copy and paste the code?

TIA

nuliknol
24th January 2015, 22:05
solved it.
apparently stylesheet text need to have new lines otherwise the QT engine doesn't interpret them

wysota
25th January 2015, 10:26
setStylesheet overrides the previously set stylesheet so only the last statement you used in your initial post has any effect.