zoukankan      html  css  js  c++  java
  • QT5-控件-QFontComboBox-字体选择下拉列表,使用一个标签查看效果

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    #include <QFontComboBox>
    #include <QFont>
    #include <QLabel>
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        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(QFontComboBox::NonScalableFonts);
        fc[3]->setFontFilters(QFontComboBox::MonospacedFonts);
        fc[4]->setFontFilters(QFontComboBox::ProportionalFonts);
    
        int ypos = 30 ;
        for(int i=0;i<5;i++)
        {
            fc[i]->setGeometry(10,ypos,300,30);
            ypos += 40 ;
        }
    
        label = new QLabel("用此标签查看字体效果",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();
    }

  • 相关阅读:
    实验 7 综合练习一
    实验或作业模版: 实验 6-1 最大公约数 最小公倍数
    实验 6 数组1
    Pro
    作业 4 函数应用
    老大
    双端队列
    zxa and leaf
    Baby Ming and Matrix games
    The more, The Better
  • 原文地址:https://www.cnblogs.com/shiyumiao/p/5207889.html
Copyright © 2011-2022 走看看