#ifndef Mainwindow_h#defineMainwindow_h#include<QMainWindow>#include<QFontComboBox>#include<QFont>#include<QLabel>classMainWindow: Publicqmainwindow{Q_object Public: MainWindow (Qwidget*parent =0); ~MainWindow (); Qfontcombobox* fc[Ten]; Qlabel*label; PublicSlots:voidChangedfont (Constqfont&f);};#endif //Mainwindow_h
#include"mainwindow.h"Mainwindow::mainwindow (Qwidget*parent): Qmainwindow (parent) { This->resize ( -, -); This-Centralwidget (); for(intI=0; i<5; i++) {Fc[i]=NewQfontcombobox ( This); } fc[0]->setfontfilters (qfontcombobox::allfonts); fc[1]->setfontfilters (qfontcombobox::scalablefonts); fc[2]->setfontfilters (qfontcombobox::nonscalablefonts); fc[3]->setfontfilters (qfontcombobox::monospacedfonts); fc[4]->setfontfilters (qfontcombobox::P roportionalfonts); intYpos = - ; for(intI=0;i<5; i++) {Fc[i]->setgeometry (Ten, Ypos, -, -); Ypos+= + ; } label=NewQlabel ("Use this tab to view font effects", This); Label->setgeometry (Ten, the, $, -); Connect (fc[0],signal (currentfontchanged (Qfont)), This, SLOT (Changedfont (Qfont)));} MainWindow::~MainWindow () {}voidMainwindow::changedfont (Constqfont&f) {Label-SetFont (f);}
" mainwindow.h " <QApplication>int main (intChar *argv[]) { qapplication a (argc, ARGV); MainWindow W; W.show (); return a.exec ();}
qt5-Control-qfontcombobox-Font selection drop-down list, use a tab to see the effect