QTreeWidget怎样设置表格线

1个回答

写回答

嘉遇

2026-02-13 22:41

+ 关注

Windows
Windows

在QTreeWidget中,可以通过设置样式来实现表格线的效果。首先需要设置父对象的样式表,然后在子对象上设置样式。以下是一个示例代码:cpp// 父对象的样式表QStyle *style = new QStyle(QStyle:: retrievesysfont(QApplication::instance(),QStyle::BaseStyle, "Windows").font(),new QStyleContext);style->setup(&app);QFont font = QStyle::styleFont(style);QFont tableFont = QFont(font, 10, QFont::Bold);QPushButton *pushButton = new QPushButton("test");QPushButton *pushButton2 = new QPushButton("test2");QPushButton *pushButton3 = new QPushButton("test3");// 子对象的样式QPushButton::SetIconSize(QSize(16,16));QPushButton::SetFixedHeight(30);QPushButton::SetFixedWidth(100);QPushButton::setMinimumSize(QSize(100,30));QPushButton::setMaximumSize(QSize(100,30));QPushButton::setToolButtonEnabled(false);QPushButton::setFixedWidth(100);QPushButton::setFixedHeight(30);QPushButton::setMinimumWidth(30);QPushButton::setMaximumWidth(30);QPushButton::setAlignment(Qt::AlignCenter);QPushButton *button1 = new QPushButton("test1");QPushButton *button2 = new QPushButton("test2");QPushButton *button3 = new QPushButton("test3");pushButton1->setStyleSheet("border:1px solid black;background-color: white;color:black;font-size:14px;border-radius:4px;");pushButton2->setStyleSheet("border:1px solid black;background-color: white;color:black;font-size:14px;border-radius:4px;");pushButton3->setStyleSheet("border:1px solid black;background-color: white;color:black;font-size:14px;border-radius:4px;");setWindowTitle("QPushButton Test");show();以上代码中,我们创建了一个父对象和三个子对象。通过设置样式,可以实现表格线的效果。在父对象的样式表中,我们设置了字体、颜色和大小等属性。在子对象的样式中,我们设置按钮边框、背景色、字体大小、圆角等属性,并且禁用了工具栏。注意:以上代码仅供参考,具体实现可能因版本不同而有所差异。

举报有用(6分享收藏

Copyright © 2025 IZhiDa.com All Rights Reserved.

知答 版权所有 粤ICP备2023042255号