首页 > 其他 > 详细

Qt之QFontDialog

时间:2020-07-08 13:29:14      阅读:73      评论:0      收藏:0      [点我收藏+]

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();
}

效果:

技术分享图片

 

Qt之QFontDialog

原文:https://www.cnblogs.com/SunShine-gzw/p/13266294.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!