#ifndef DIALOG_H #define DIALOG_H #include <QDialog> #include<QPushButton> #include<QLineEdit> #include<QFontDialog> #include<QGridLayout> class Dialog : public QDialog { Q_OBJECT public: Dialog(QWidget *parent = 0); ~Dialog(); private: QGridLayout *glayout; QPushButton *fontButton; QLineEdit *fontlineEdit; private slots: void dispFontFunc(); }; #endif // DIALOG_H
#include "dialog.h" #include <QFontDialog> Dialog::Dialog(QWidget *parent) : QDialog(parent) { setWindowTitle("字体对话框测试"); glayout =new QGridLayout(this); fontButton=new QPushButton("字体对话框"); fontlineEdit=new QLineEdit; fontlineEdit->setText("看字体"); glayout->addWidget(fontButton,0,0); glayout->addWidget(fontlineEdit,0,1); connect(fontButton,SIGNAL(clicked()),this,SLOT(dispFontFunc())); } Dialog::~Dialog() { } void Dialog::dispFontFunc() { bool isbool; QFont font=QFontDialog::getFont(&isbool); if(isbool){ fontlineEdit->setFont(font); } }
标签:glayout,对话框,fontlineEdit,字体,QFontDialog,Dialog,fontButton,include From: https://www.cnblogs.com/baisedeyu/p/17884441.html