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

时间: 2024-08-24 22:33:06

QT5-控件-QFontComboBox-字体选择下拉列表,使用一个标签查看效果的相关文章

如何修改全部DevExpress控件的字体

引用:https://www.devexpress.com/Support/Center/Question/Details/A2761 You can change the default font used by DevExpress WindowsForms controls with the following static properties: DevExpress.XtraEditors.WindowsFormsSettings.DefaultFont - Specifies the

根据ui控件的字体计算占用的长度

//1.根据icon计算name的长度 CGFloat nameX = CGRectGetMaxX(_icon.frame) + kBorder; CGFloat nameY = iconY; //计算用户昵称的长度 CGSize nameSize = [_weiBo.name sizeWithFont:_name.font]; _name.frame = CGRectMake(nameX, nameY, nameSize.width, nameSize.height); //2.设置vip的f

CheckBoxList控件获取多选择,需要遍历

CheckBoxList控件获取多选择,需要遍历,环境:vs2008 在页面上添加CheckBoxList控件,输入项值 a,b,c,d.然后添加按钮 Button2确定,如何获取CheckBoxList控件多选择呢? protected void Button2_Click(object sender, EventArgs e)    {        string ChbSelected = "";        for (int i = 0; i < CheckBoxLis

bootstrap-表单控件——下拉选择框select元素

1.运行效果如图所示 2.实现代码如下 <!DOCTYPE html> <html> <head>     <meta charset="utf-8">     <meta http-equiv="X-UA-Compatible" content="IE=edge">     <title>表单控件--下拉选择框select元</title>     <!-

[原]C#按比例缩放窗体控件及字体

按照比例缩放窗体控件及字体,如需等比例缩放,只需将x,y的比例设置成相同即可. 为了减小误差,建议使用原始尺寸来计算比例. 1 private float X, Y; 2 3 private bool b = false; 4 5 public MainForm() 6 { 7 InitializeComponent(); 8 9 X = this.Width; 10 Y = this.Height; 11 12 SetTag(this); 13 14 b = true; 15 } 16 17

Scroll View 控件以Thumbnail的方式显示一个文件夹的所有图片,类似图片浏览器

MAC : XCode -> Scroll View 控件以Thumbnail的方式显示一个文件夹的所有图片,类似图片浏览器 STEP1:将两个文件夹拷贝到工程里面ImageBrowserView和Utils,并且在工程里面建立对应组和导入文件 STEP2:将Quartz.framework 和QuartzCore.framework库 导入到工程里面,这两个库是系统库 STEP3:   找到控件Scroll View 控件,上面写着"Scroll View"拖入到工程里面,然后

WinForm开发中针对TreeView控件改变当前选择节点的字体与颜色

本文转载:http://www.cnblogs.com/umplatform/archive/2012/08/29/2660240.html 在B/S开发中,对TreeView控件要改变当前选中节点的颜色比较方便,其有相应的SelectedNodeChanged事件进行控制,但对于WinForm则没有这样方便.申明一下,我在这儿所说的改变当前节点的字体与颜色,主要是在WinForm中的TreeView控件,当前选中节点后,其失去鼠标焦点后节点的字体与颜色失去了选中状态,层级一多,我们就不知道当前

【MFC系列】MFC快速设置控件文本字体、大小、颜色、背景

以静态文本为例,分享一下怎么修改文本字体.大小.颜色.背景等参数.其他文本.控件等可参照修改. 1.修改字体.大小 这个很简单,首先在Dlg类中声明一个CFont类型的成员变量: 然后在类的初始化函数OnInitDialog()中添加以下两行代码: 1 //设置静态文本字体大小 2 m_editFont.CreatePointFont(180, _T("宋体")); 3 m_Static.SetFont(&m_editFont); 2.改变编辑框文本颜色.背景颜色 右键点击该对

DropDrowList控件添加“请选择” 新写法

this.DropDrowListNews.Items.Insert(0 ,new ListItem("请选择","0")); 写法说明: this.DropDrowListNews.Items 当前控件集合.Insert(插入) (“将信息插入第几个下标” ,  创建一个结合 new ListItem(“插入vlaue”,"0")注意格式:new ListItem(string Text,string value)  ;