简体   繁体   中英

set line between qtreewidget items

I have a QTreeWidget that items append to it dynamically, I want to set lines between them, I have first pictures and I want it to be like the second one, but I don't know how doing it? thank you in advance!

[我有这棵树

[我希望我的树像这样

Well you can experiment with stylesheets:

treeWidget->setStyleSheet("QTreeWidget::item { border-bottom: 1px solid black;}");

But I am not sure if can get exactly the look you want. You can also subclass QStyledItemDelegate and provide your own sizeHint() and paint() implementations.

If You need to select items, following works a little better I think:

  QString style = "QTreeWidget::item:!selected "
    "{ "
      "border: 1px solid gainsboro; "
      "border-left: none; "
      "border-top: none; "
    "}"
    "QTreeWidget::item:selected {}";
  allergiesListView->setStyleSheet(style);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM