任何人都可以帮我qt [英] can anyone help me with qt

查看:119
本文介绍了任何人都可以帮我qt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将文本的颜色更改为蓝色,我在qt edittext中得到class这个词,但我无法找到任何方法来实现它,





i我是qt的新手,有谁可以请帮助我

这里是我打开的文件代码



I want to change the color of text to blue where ever i get the word "class" in qt edittext , but i cant find any way to do it ,


i am new in qt , can anyone please help me
here is my code of file open

void MainWindow::on_actionOpen_triggered()
{
    QString file = QFileDialog::getOpenFileName(this,"Qpen a file please");
    if(!file.isEmpty())
    {
        QFile sFile(file);
        if(sFile.open(QFile::ReadOnly | QFile::Text))
        {
            mFilename = file;
            QTextStream in(&sFile);
            QString text = in.readAll();
            sFile.close();
            ui->textEdit->setPlainText(text);
        }
    }
}

推荐答案

这需要 QTextEdit 使用HTML文本(也称为带有Qt的RichText)。



加载纯文本文件时,必须将其转换为HTML并应用所需的格式(例如将class替换为< font color = \ blue\ >类< /字体> 中)。然后使用 setHtml()而不是 setPlainText()。有关支持的HTML样式,请参阅Qt文档(它只是CSS的一个子集)。
This requires that the QTextEdit uses HTML text (also called RichText with Qt).

When loading a plain text file you must convert it to HTML and apply the required formats (e.g. by replacing "class" with "<font color=\"blue\">class</font>"). Then use setHtml() instead of setPlainText(). See the Qt documentation for the supported HTML styles (it is only a subset of CSS).


这篇关于任何人都可以帮我qt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆