Qt QTableView样式设置

                        Qt QTableView样式设置

 

显示效果

QSS设置

 

选中设置:

1

2

3

4

5

QTableView::item:selected

{

    background:rgb(0,0,100);

    color:white;

}

表头设置:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

QHeaderView::section:first

{

    border-image: url(:/images/expand/tempUser_headBg2.png);

    height: 30px;

    font: 11pt "微软雅黑";

}

 

QHeaderView::section:middle

{

    border-image: url(:/images/expand/tempUser_headBg2.png);

    height: 30px;

    font: 11pt "微软雅黑";

}

 

QHeaderView::section:last

{

    border-image: url(:/images/expand/tempUser_headBg4.png);

    height: 30px;

    font: 11pt "微软雅黑";

}

滚动条设置:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

QScrollBar:vertical {

    border: 0px;

    background:rgba(255,255,255,0);

    border-image:url(:/images/scrollbar/vertical_scrollBg.png);

    width: 22px;

    margin: 22px 0  22px 0;

}

 

QScrollBar::handle:vertical {

     border-image:url(:/images/scrollbar/vertical_slide.png);

    width:22px;

min-height:50px;

max-height:200px;

 }

 

QScrollBar::handle:vertical:hover {

    border-image: url(:/images/scrollbar/vertical_slide_hover.png);

     width:22px;

min-height:50px;

max-height:200px;

 }

 

QScrollBar::handle:horizontal:hover {

    border-image: url(:/images/scrollbar/slide.png);

     width:22px;

min-height:35px;

 }

 

QScrollBar::handle:vertical:hover {

     border-image:url(:/images/scrollbar/vertical_slide_hover.png);

    width:22px;

 }

 

 QScrollBar::add-line:vertical {

     border-image:url(:/images/scrollbar/vertical_down.png);

     height: 22px;

     subcontrol-position: bottom;

     subcontrol-origin: margin;

 

 }

 QScrollBar::add-line:vertical:pressed{

     border-image:url(:/images/scrollbar/vertical_down_down.png);

     height: 22px;

     subcontrol-position: bottom;

     subcontrol-origin: margin;

 

 }

 QScrollBar::sub-line:vertical {

      border-image:url(:/images/scrollbar/vertical_up.png);

     height:22px;

     subcontrol-position: top;

     subcontrol-origin: margin;

 }

 QScrollBar::sub-line:vertical:pressed {

      border-image:url(:/images/scrollbar/vertical_up_down.png);

     height: 22px;

     subcontrol-position: top;

     subcontrol-origin: margin;

 }

QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {

     background: none;

 }

 

QScrollBar:horizontal {

    border: 0px;

    background:rgba(255,255,255,0);

    border-image:url(:/images/scrollbar/scrollBg.png);

    height: 22px;

    margin: 0 22px 0  22px;

}

 

QScrollBar::handle:horizontal {

     border-image:url(:/images/scrollbar/slide.png);

    height:22px;

 }

 

QScrollBar::handle:vertical:hover {

     border-image:url(:/images/scrollbar/vertical_slide_hover.png);

    width:22px;

 }

 

 QScrollBar::add-line:horizontal {

     border-image:url(:/images/scrollbar/down.png);

     width: 22px;

     subcontrol-position: right;

     subcontrol-origin: margin;

 

 }

 QScrollBar::add-line:horizontal:pressed{

     border-image:url(:/images/scrollbar/down_down.png);

     width: 22px;

     subcontrol-position: right;

     subcontrol-origin: margin;

 

 }

 QScrollBar::sub-line:horizontal {

      border-image:url(:/images/scrollbar/up.png);

     width:22px;

     subcontrol-position: left;

     subcontrol-origin: margin;

 }

 QScrollBar::sub-line:horizontal:pressed {

      border-image:url(:/images/scrollbar/up_down.png);

     width: 22px;

     subcontrol-position: left;

     subcontrol-origin: margin;

 }

QScrollBar::add-page:horizontal, QScrollBar::sub-page:horizontal {

     background: none;

 }

行之间颜色渐变(alternaingRowColors必须设置为true):

1

2

3

4

5

QTableView

{

    background-color: rgb(255, 255, 255);

    alternate-background-color:#F2F8FF;

}

 设置QTreeWidget水平滚动条: 

1

2

ui.treeWidget_site->header()->setSectionResizeMode(QHeaderView::ResizeToContents); 

ui.treeWidget_site->header()->setStretchLastSection(false);

  代码设置

void MainWindow::initUi()
{

//    // 表头
//   ui->tableWidget->setColumnCount(m_iColumCount);
//   ui->tableWidget->setRowCount(1);
//   ui->tableWidget->verticalHeader()->setVisible(false);
//   ui->tableWidget->horizontalHeader()->setVisible(false);
//   ui->tableWidget->setFrameShape(QFrame::NoFrame);
//   ui->tableWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
//   ui->tableWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
//   ui->tableWidget->setSelectionMode(QAbstractItemView::NoSelection);
//   ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
//   ui->tableWidget->setFocusPolicy(Qt::NoFocus);


    QStandardItemModel* model = new QStandardItemModel();

    /* 设置列数 */
    model->setColumnCount(14);
    model->setHeaderData(0, Qt::Horizontal, QStringLiteral("任务编号"));
    model->setHeaderData(1, Qt::Horizontal, QStringLiteral("任务类型"));
    model->setHeaderData(2, Qt::Horizontal, QStringLiteral("工作模式"));
    model->setHeaderData(3, Qt::Horizontal, QStringLiteral("中频频率"));
    model->setHeaderData(4, Qt::Horizontal, QStringLiteral("中频带宽"));
    model->setHeaderData(5, Qt::Horizontal, QStringLiteral("中频增益"));
    model->setHeaderData(6, Qt::Horizontal, QStringLiteral("调制类型"));
    model->setHeaderData(7, Qt::Horizontal, QStringLiteral("调制速率"));
    model->setHeaderData(8, Qt::Horizontal, QStringLiteral("发射频率"));
    model->setHeaderData(9, Qt::Horizontal, QStringLiteral("发射功率"));
    model->setHeaderData(10, Qt::Horizontal, QStringLiteral("成型系数"));
    model->setHeaderData(11, Qt::Horizontal, QStringLiteral("任务状态"));
    model->setHeaderData(12, Qt::Horizontal, QStringLiteral("开始时间"));
    model->setHeaderData(13, Qt::Horizontal, QStringLiteral("结束时间"));



    /* 设置行数 */
    model->setRowCount(14);
    model->setHeaderData(0, Qt::Vertical, QStringLiteral("1"));

    ui->tableView->horizontalHeader()->setStyleSheet("QHeaderView::section {"
                                                           "color: #44b4da; background-color: rgb(21, 45, 93);padding-left: 4px;border: 1px solid #44b4da;}");


    ui->tableView->setModel(model);
    /* 设置列宽在可视界面自适应宽度 */
//    ui->tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
    ui->tableView->horizontalHeader()->setResizeContentsPrecision(QHeaderView::Stretch);
    /* 行颜色交替显示 */
    ui->tableView->setAlternatingRowColors(true);
    /* 不允许在图形界面修改内容 */
    ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);

    /* 在表格内加入内容 */
    model->setItem(0, 0, new QStandardItem(QStringLiteral("数字")));

    /* 显示表 */
    ui->tableView->show();
}

工程代码下载

 

参考

转载请注明出处:http://www.cnblogs.com/dachen408/p/7591409.html

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值