Linux下定制QTableWidget

http://blog.csdn.net/yavobo/archive/2011/02/16/6188596.aspx

 

 

定制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();
}

 

Linux下定制QTableWidget_第1张图片

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/yavobo/archive/2011/02/16/6188596.aspx

你可能感兴趣的:(Linux下定制QTableWidget)