我的设置样式源码:
void QTableWidgetNew::InitStyle(int rowHeight)
{
this->setSelectionBehavior(QAbstractItemView::SelectRows);
this->setSelectionMode(QAbstractItemView::ExtendedSelection);
this->setShowGrid(false);
this->setEditTriggers(QAbstractItemView::NoEditTriggers);
this->setStyle(new QCleanlooksStyle);
this->setRowHeight(0, rowHeight);
this->verticalHeader()->setVisible(false); //false
this->horizontalHeader()->setVisible(true); //true
this->horizontalHeader()->setHighlightSections(false);
this->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);//
this->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);//
this->horizontalHeader()->setResizeMode(QHeaderView::Fixed);
this->setStyleSheet(" font-size: 12px; \
background: white;\
border:0px solid;\
background-image: url(:/message/message/list_menu_bg02.bmp); \
selection-background-color: \
qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, \
stop: 0 #A5B6D6, stop: 0.5 #94A6C6, \
stop: 0.6 #94A6C6, stop: 1 #738EB5 );\
");
this->horizontalHeader()->setStyleSheet(" \
QHeaderView::section { \
background: #F7F7F7;\
background-color: #F7F7F7; \
color: black; \
border: 1px inset #DEDEDE; \
height: 14px;\
font: Fixed Arial;\
} \
");
this->verticalScrollBar()->setStyleSheet(" \
QScrollBar:vertical{ \
border: 1px insert white; \
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,\
stop: 0 #F7EFEF, stop: 0.5 #F7F7F7,\
stop: 0.6 #F7F7F7, stop: 1 #E7EFEF);\
width: 17px; \
margin: 17px 0 17px 0; \
} \
QScrollBar::handle:vertical { \
border: 1px solid grey;\
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,\
stop: 0 #F7F7EF, stop: 0.5 #EFEFEF,\
stop: 0.6 #EFEFEF, stop: 1 #E7E7E7);\
min-height: 20px;\
}\
QScrollBar::add-line:vertical {\
border: 0px insert grey;\
background: white;\
height: 17px;\
subcontrol-position: bottom;\
subcontrol-origin: margin;\
}\
QScrollBar::sub-line:vertical {\
border: 0px insert grey;\
background: white;\
height: 17px;\
subcontrol-position: top;\
subcontrol-origin: margin;\
}\
QScrollBar::up-arrow:vertical{ \
width: 17px; \
height: 17px; \
background: white;\
image: url(:/common/common/scroll_up.bmp);\
}\
QScrollBar::down-arrow:vertical { \
width: 17px; \
height: 17px; \
background: white;\
image: url(:/common/common/scroll_down.bmp);\
}\
QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {\
background: white;\
}\
");
}