您的位置:首页 > 编程语言 > Qt开发

QT设置字体与颜色

2017-08-04 16:11 309 查看
头文件:

#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;

    }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: