QT设置字体与颜色

来源:互联网 发布:淘宝的鹰眼系统 编辑:程序博客网 时间:2024/05/19 19:39
头文件:
#include <QFont>
#include <QFontDialog>
#include <QColor>
#include <QColorDialog>




user interface complier


QColor
QFont
QFontDialog
QDataTime




程序代码:


//设置字体
void MainWindow::setFontSlot()
{
     //get user select Font


    bool ok;
    QFont font = QFontDialog::getFont(&ok,this);
    if(ok)
    {
        ui->textEdit->setFont(font);
        //font is set to the font the user selected
    }
    else
    {
        QMessageBox::information(this,"Error Message","Eoor Set Font!!!")
        //the user canceld the dialog;font is set to the default
        //application font,QApplication::font()
    }
}


//设置颜色
void MainWindow::setColorSlot()
{


    QColor color = QColorDialog::getColor(Qt::red,this);        //设置初始化颜色为红色
    if(color.isValid())
    {
        ui->textEdit->setTextColor(color);
    }
    else
    {
        QMessageBox::information(this,"Error Message","Color is Invalid");
        return;
    }
}
原创粉丝点击