QT5-control-QFontComboBox-font select drop-down list, use a label to view the effect, qtcombobox drop-down event
#ifndef MAINWINDOW_H#define MAINWINDOW_H#include <QMainWindow>#include <QFontComboBox>#include <QFont>#include <QLabel>class MainWindow : public QMainWindow{ Q_OBJECTpublic: MainWindow(QWidget *parent = 0); ~MainWindow(); QFontComboBox* fc[10]; QLabel* label ;public slots: void changedFont(const QFont& f);};#endif // MAINWINDOW_H
# Include "mainwindow. h "MainWindow: MainWindow (QWidget * parent): QMainWindow (parent) {this-> resize (400,300); this-> centralWidget (); for (int I = 0; I <5; I ++) {fc [I] = new QFontComboBox (this);} fc [0]-> setFontFilters (QFontComboBox: AllFonts ); fc [1]-> setFontFilters (QFontComboBox: ScalableFonts); fc [2]-> setFontFilters (usage: NonScalableFonts); fc [3]-> setFontFilters (usage: MonospacedFonts ); Fc [4]-> setFontFilters (QFontComboBox: ProportionalFonts); int ypos = 30; for (int I = 0; I <5; I ++) {fc [I]-> setGeometry (10, ypos, 30); ypos + = 40;} label = new QLabel ("use this label to view font effects", this ); label-> setGeometry (10,230,200, 30); connect (fc [0], SIGNAL (currentFontChanged (QFont), this, SLOT (changedFont (QFont);} MainWindow :: ~ MainWindow () {} void MainWindow: changedFont (const QFont & f) {label-> setFont (f );}
#include "mainwindow.h"#include <QApplication>int main(int argc, char *argv[]){ QApplication a(argc, argv); MainWindow w; w.show(); return a.exec();}