定制QTableWidget

#include <QApplication> #include <QMainWindow> #include <QTableWidget> #include <QDockWidget> #include <QTreeWidget> #include <QList> #include <QStringList> #include <QHeaderView> int main(int argc, char *argv[]) { QApplication a(argc, argv); QMainWindow w; QTableWidget table; QDockWidget dock; QTreeWidget tree; table.setRowCount(200); table.setColumnCount(26); tree.setColumnCount(1); QList<QTreeWidgetItem *> items; for (int i = 0; i < 10; ++i) items.append(new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString("item: %1").arg(i)))); tree.insertTopLevelItems(0, items); tree.setColumnCount(5); //border-bottom:1px solid #000000; //border-right:1px solid #000000; a.setStyleSheet("QTreeWidget::item{border-bottom:1px solid #aaa;border-right:1px solid #aaa;height: 24px;}"); table.horizontalHeader()->setStyleSheet("QHeaderView::section {background-color:darkgrey;" "color: red;padding-left: 4px;border-left: 1px solid #aaa;height:24px;}"); /*"QHeaderView::section{background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1," "stop:0 #fff, stop: 0.5 #aaa,stop: 0.6 000, stop:1 #aaa);" "color: red;padding-left: 5px;border-left: 1px solid #aaa;height: 24px;}");*/ table.verticalHeader()->setStyleSheet("QHeaderView::section {background-color:darkgrey;" "color: red;padding-left: 4px;border-bottom: 1px solid #aaa;}"); dock.setWidget(&tree); dock.setWindowTitle("Tools"); w.addDockWidget(Qt::LeftDockWidgetArea, &dock); w.setCentralWidget(&table); w.statusBar(); w.show(); return a.exec(); }

定制QTableWidget_第1张图片

你可能感兴趣的:(tree,table,qt,include,tools)