zoukankan      html  css  js  c++  java
  • QTableWidget 使用及美化_QtableWidget_QtableView滚动条宽度及样式

     
    //创建及属性设置
    m_tableWidget = new QTableWidget(this);
    m_tableWidget->setRowCount(10);
    m_tableWidget->setColumnCount(3);
    //m_tableWidget->setFrameShape(QFrame::NoFrame); //设置边框
    //m_tableWidget->setShowGrid(false); //设置不显示格子线
    //QPalette pll = m_tableWidget->palette();
    //pll.setBrush(QPalette::Base,QBrush(QColor(255,255,255,0)));
    //m_tableWidget->setPalette(pll);
    //m_tableWidget->horizontalHeader()->setStyleSheet("QHeaderView::section {background-color:lightblue;color: black;padding-left: 4px;border: 1px solid #6c6c6c;}");


    m_tableWidget->horizontalHeader()->setDefaultSectionSize(150);
    m_tableWidget->horizontalHeader()->setClickable(false); //设置表头不可点击(默认点击后进行排序)

    //设置表头内容
    QStringList header;
    header<<tr("Index")<<tr("Name")<<tr("Time");
    m_tableWidget->setHorizontalHeaderLabels(header);

    //设置表头字体加粗
    QFont font = m_tableWidget->horizontalHeader()->font();
    font.setBold(true);
    m_tableWidget->horizontalHeader()->setFont(font);

    m_tableWidget->horizontalHeader()->setStretchLastSection(true); //设置充满表宽度
    m_tableWidget->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
    m_tableWidget->verticalHeader()->setDefaultSectionSize(10); //设置行距
    m_tableWidget->setFrameShape(QFrame::NoFrame); //设置无边框
    m_tableWidget->setShowGrid(false); //设置不显示格子线
    m_tableWidget->verticalHeader()->setVisible(false); //设置垂直头不可见
    m_tableWidget->setSelectionMode(QAbstractItemView::ExtendedSelection); //可多选(Ctrl、Shift、 Ctrl+A都可以)
    m_tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows); //设置选择行为时每次选择一行
    m_tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers); //设置不可编辑
    m_tableWidget->horizontalHeader()->resizeSection(0,20); //设置表头第一列的宽度为150
    m_tableWidget->horizontalHeader()->resizeSection(2,50); //设置表头第一列的宽度为150
    m_tableWidget->horizontalHeader()->setFixedHeight(25); //设置表头的高度

    //m_tableWidget->setStyleSheet("background: rgb(56,56,56);alternate-background-color:rgb(48,51,55);selection-background-color:qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 rgb(56,56,56),stop:1 rgb(76,76,76));"); //设置选中背景色
    //m_tableWidget->horizontalHeader()->setStyleSheet("QHeaderView::section{background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 rgb(46,46,46),stop:1 rgb(66,66,66));color: rgb(210,210,210);;padding-left: 4px;border: 1px solid #383838;}"); //设置表头背景色
    m_tableWidget->setAlternatingRowColors(true);
    m_tableWidget->setFocusPolicy(Qt::NoFocus); //去除选中虚线框

    //设置水平、垂直滚动条样式
    //m_tableWidget->horizontalScrollBar()->setStyleSheet("QScrollBar{background:red; height:10px;}"
    // "QScrollBar::handle{background:lightgray; border:2px solid transparent; border-radius:5px;}"
    // "QScrollBar::handle:hover{background:gray;}"
    // "QScrollBar::sub-line{background:transparent;}"
    // "QScrollBar::add-line{background:transparent;}");
    //m_tableWidget->verticalScrollBar()->setStyleSheet("QScrollBar{background:red; 10px;}"
    // "QScrollBar::handle{background:lightgray; border:2px solid transparent; border-radius:5px;}"
    // "QScrollBar::handle:hover{background:gray;}"
    // "QScrollBar::sub-line{background:transparent;}"
    // "QScrollBar::add-line{background:transparent;}");
    /*QPalette pal;
    pal.setColor(QPalette::Base, QColor(255, 0, 0));
    pal.setColor(QPalette::AlternateBase, QColor(0, 255, 0));
    m_tableWidget->setPalette(pal);*/
    m_tableWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    m_tableWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    m_tableWidget->setAlternatingRowColors(true);
    m_tableWidget->setShowGrid(false);
  • 相关阅读:
    迭代器简介
    关于判断对象是否相等的问题
    NIO
    BIO流分类介绍
    servlet简介
    http协议简介
    爬虫常用链接
    http和https协议
    爬虫的合法性研究
    爬虫介绍
  • 原文地址:https://www.cnblogs.com/yelanggu/p/4056810.html
Copyright © 2011-2022 走看看