zoukankan      html  css  js  c++  java
  • Qt之QFontDialog

    widget.h:

    #ifndef WIDGET_H
    #define WIDGET_H
    
    #include <QWidget>
    
    class Widget : public QWidget
    {
        Q_OBJECT
    public slots:
    void showFontDialog();
    public:
        Widget(QWidget *parent = 0);
        ~Widget();
    };
    
    #endif // WIDGET_H

    widget.cpp:

    #include "widget.h"
    #include<QFont>
    #include<QDebug>
    #include<QPushButton>
    #include<QVBoxLayout>
    #include<QFontDialog>
    #include<QFontDatabase>
    
    Widget::Widget(QWidget *parent)
        : QWidget(parent)
    {
        this->resize(600,480);
    QFont qf=this->font();
    qf.setFamily("仿宋");
    qf.setPointSize(30);
     this->setFont(qf);
    
     //QFontDatabase db; //系统字体数据库
    //qDebug()<<db.families()<<endl;
    QPushButton *qp_one=new QPushButton("用户名");
    QPushButton *qp_two=new QPushButton("密码");
    QVBoxLayout *qv=new QVBoxLayout(this);
    qv->addWidget(qp_one);
    qv->addWidget(qp_two);
    this->setLayout(qv);
    connect(qp_one,SIGNAL(clicked()),this,SLOT(showFontDialog()));
    connect(qp_two,SIGNAL(clicked()),this,SLOT(showFontDialog()));
    }
    void Widget::showFontDialog()
    {
        bool ok;
       // QFont qf=QFontDialog::getFont(&ok,this);
         QFont qf=QFontDialog::getFont(&ok,this->font(),this,"ff");
        if(ok)
        {
            this->setFont(qf);
        }
    
    }
    Widget::~Widget()
    {
    
    }

    main.cpp:

    #include "widget.h"
    #include <QApplication>
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        Widget w;
        w.show();
    
        return a.exec();
    }

    效果:

  • 相关阅读:
    20181205关于android动态权限管理的总结与思考。
    pixel2坑
    Picasso遇到的坑
    集成主流框架搭建项目
    outdoor-youwin
    利用scatter()绘制颜色映射的二次方曲线
    一个有意义的Day类
    [Hadoop] Yarn & k8s
    hadoop 操作
    yarn 图形化监控
  • 原文地址:https://www.cnblogs.com/SunShine-gzw/p/13266294.html
Copyright © 2011-2022 走看看