QT5-control-QFontComboBox-font select drop-down list, use a label to view the effect, qtcombobox drop-down event

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.