QTreeWidget 样式设置记录

先看效果图

1.item 高度的设置

2.选中的样式

3.去掉焦点状态(否则选中后有个灰框在上面)

 

 

QStringList hraders;
    hraders<<"key" << "值"<< "";
    ui->treeWidgetAdptive->setHeaderLabels(hraders);		//添加树表的表头
    ui->treeWidgetAdptive->setColumnWidth(0,400*getFactorX());
    ui->treeWidgetAdptive->setColumnWidth(1,200*getFactorX());
    ui->treeWidgetAdptive->headerItem()->setTextAlignment(0,Qt::AlignCenter);
    ui->treeWidgetAdptive->headerItem()->setTextAlignment(1,Qt::AlignCenter);
    ui->treeWidgetAdptive->headerItem()->setFont(0,ui->treeWidgetAdptive->font());
    ui->treeWidgetAdptive->headerItem()->setFont(1,ui->treeWidgetAdptive->font());
    ui->treeWidgetAdptive->setFocusPolicy(Qt::NoFocus);

    ui->treeWidgetAdptive->setSelectionBehavior(QAbstractItemView::SelectRows);
    ui->treeWidgetAdptive->setSelectionMode(QAbstractItemView::SingleSelection);
    ui->treeWidgetAdptive->setStyleSheet(QString(
                                             "QTreeView{"
                                             "font-size:%2px;"
                                             "show-decoration-selected:1;"
                                             "selection-background-color:qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1,stop:0 rgba(255, 255, 255, 255), stop:0.5 rgba(235, 247, 253, 255), stop:1 rgba(213, 237, 250, 255));"
                                             "color:black; "
                                             "background-color: rgb(255, 255, 255);	"
                                             "}"
                                             "  QTreeView::item {"
                                             "      height:%1px;"
                                             "       border: 1px solid rgb(200, 200, 200);"
                                             "      border-left-color: transparent;"
                                             "      border-top-color: transparent;"
                                             "  }"
                                             "  QTreeView::item:selected {"
                                             "      background:rgb(255,255,255);"
                                             "background-color:qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1,stop:0 rgba(255, 255, 255, 255), stop:0.5 rgba(235, 247, 253, 255), stop:1 rgba(213, 237, 250, 255));"
                                             "border: 1px solid rgb(65,173,255);"
                                             "}"
                                             ""
                                             "  QTreeView::item:selected:active{"
                                             "color:rgb(0,0,0);"
                                             "background-color:qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1,stop:0 rgba(255, 255, 255, 255), stop:0.5 rgba(235, 247, 253, 255), stop:1 rgba(213, 237, 250, 255));"
                                             "border: 1px solid rgb(65,173,255);"
                                             "}"
                                             ""
                                             "  QTreeView::item:selected:!active {"
                                             "       color:rgb(0,0,0);"
                                             "background-color:qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1,stop:0 rgba(255, 255, 255, 255), stop:0.5 rgba(235, 247, 253, 255), stop:1 rgba(213, 237, 250, 255));"
                                             "border: 1px solid rgb(65,173,255);"
                                             "}"
                                             "  QTreeView::branch:has-siblings:!adjoins-item {"
                                             "      border-image: url(:/image/icons/vline.png) 0;"
                                             "  }"
                                             ""
                                             "  QTreeView::branch:has-siblings:adjoins-item {"
                                             "      border-image: url(:/image/icons/branch-more.png) 0;"
                                             "  }"
                                             ""
                                             "  QTreeView::branch:!has-children:!has-siblings:adjoins-item {"
                                             "      border-image: url(:/image/icons/branch-end.png) 0;"
                                             "  }"
                                             ""
                                             "  QTreeView::branch:has-children:!has-siblings:closed,"
                                             "  QTreeView::branch:closed:has-children:has-siblings {"
                                             "          border-image: none;"
                                             "          image: url(:/image/icons/branch-closed.png);"
                                             "  }"
                                             ""
                                             "  QTreeView::branch:open:has-children:!has-siblings,"
                                             "  QTreeView::branch:open:has-children:has-siblings  {"
                                             "          border-image: none;"
                                             "          image: url(:/image/icons/branch-open.png);"
                                             "  }"


                                             "QHeaderView::section {background-color:rgb(220,221,221);"
                                             "      height:%1px;"
                                             "border-color:rgb(200,199,199);"
                                             "border-style:solid;"
                                             "border-width:1px;}"
                                             ).arg(40*getFactorY()).arg(20*getFactorY()));

    QString sheet;
    sheet = QString ("QScrollBar:vertical{min-width:%1px;min-height:%2px;background-color:rgba(239, 239, 239, 255); margin:0px,0px,0px,0px;border: 1px solid rgb(185, 185, 185);}\
QScrollBar::handle:vertical{min-height:%2px;background-color:qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(250, 250, 250, 255), stop:0.5 rgba(210, 210, 210, 255), stop:1 rgba(208, 208, 208, 255));\
border: 1px solid rgb(185, 185, 185); border-left: rgba(0, 0, 0, 0);}\
QScrollBar::add-line:vertical { height:0px; subcontrol-position:bottom;}\
QScrollBar::sub-line:vertical  { height:0px; subcontrol-position:top;}")
                .arg(16*getFactorX()).arg(50*getFactorX());
    ui->treeWidgetAdptive->verticalScrollBar()->setStyleSheet(sheet);

 

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 书香水墨 设计师:CSDN官方博客 返回首页