• 给View换字体


    注意,给View换字体是直接换。在Delegate里换的只是某一列的字体

    class delegate : public QStyledItemDelegate
    {
    public:
    delegate(QObject* parent = 0) : QStyledItemDelegate(parent)
    {}
    
    void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
    {
    QStyledItemDelegate::paint(painter, option, index);
    }
    };
    
    int main(int argc, char* argv[])
    {
    QApplication a(argc, argv);
    
    QStringList list;
    list << "a" << "b" << "c";
    
    QListWidget w;
    w.setFont(QFont("Courier", 30));
    delegate d;
    w.setItemDelegate(&d);
    w.addItems(list);
    w.show();
    
    QListView lv;
    lv.setFont(QFont("Courier", 30));
    lv.setItemDelegate(&d);
    QStringListModel m;
    m.setStringList(list);
    lv.setModel(&m);
    lv.show();
    
    
    return a.exec();
    }

    参考:http://www.qtcentre.org/archive/index.php/t-29871.html

    -----------------------------------------------------------------------

    Delegate里也能换字体,但换的是progress自己的字体(如果用到的话),并不对整个view起作用,例如:

    void ProgressBarDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
    {  
        if (index.column() == 3) {    
        else {
            // good 这里换字体是换进度条(第三列)的字体,但是能起作用
            painter->save();
            painter->setFont(QFont("Times", 10, QFont::Bold));
            return QStyledItemDelegate::paint(painter, option, index);
            painter->restore();
        }
    }

    ------------------------------------------------------------------------

    另外,设置QTableView的行高是:

    QTtableView的verticalHeader()->setDefaultSectionSize(15),既可以放在构造函数里,也可以构造完毕后调用。

  • 相关阅读:
    团队项目第二阶段——第十天
    团队项目第二阶段——第九天
    团队项目第二阶段——第八天
    团队项目第二阶段——第七天
    第十五周学习进度总结
    团队项目第二阶段——第六天
    团队项目第二阶段——第五天
    找水王
    团队项目第二阶段——第四天
    团队项目第二阶段——第三天
  • 原文地址:https://www.cnblogs.com/findumars/p/4058425.html
Copyright © 2020-2023  润新知