当前位置: 首页>>代码示例>>C++>>正文


C++ QTextCursor::setCharFormat方法代码示例

本文整理汇总了C++中QTextCursor::setCharFormat方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextCursor::setCharFormat方法的具体用法?C++ QTextCursor::setCharFormat怎么用?C++ QTextCursor::setCharFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QTextCursor的用法示例。


在下文中一共展示了QTextCursor::setCharFormat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: updateServer

void ChatTextEdit::updateServer(const ServerProperties& srvprop)
{
    appendPlainText("");

    QString dt = getTimeStamp();
    
    QTextCharFormat format = textCursor().charFormat();
    QTextCharFormat original = format;
    QTextCursor cursor = textCursor();
    
    //show 'joined new channel' in bold
    QFont font = format.font();
    font.setBold(true);
    format.setFont(font);
    cursor.setCharFormat(format);
    QString line = dt + tr("Server Name: %1").arg(_Q(srvprop.szServerName));;
    setTextCursor(cursor);
    appendPlainText(line);

    line = dt + tr("Message of the Day: %1").arg(_Q(srvprop.szMOTD)) + "\r\n";
    format.setForeground(QBrush(Qt::darkCyan));
    cursor.setCharFormat(format);
    setTextCursor(cursor);
    appendPlainText(line);

    //revert bold
    font.setBold(false);
    format.setFont(font);

    //revert to original
    cursor.setCharFormat(original);
    setTextCursor(cursor);
    limitText();
}
开发者ID:BearWare,项目名称:TeamTalk5,代码行数:34,代码来源:chattextedit.cpp

示例2: appendMessageToCurrentSession

/*! Append a new message to the current session and scroll to the end of the message protocol and
    returns true if the action was successful. The \a messageColor defines the color of the message
    box and should be provided as a full-color (no dimming required) color, as it is automatically
    adjusted for the border and background.
*/
bool QwcPrivateMessager::appendMessageToCurrentSession(QTextDocument *document, const QString message, const QColor messageColor)
{
    if (!document) { return false; }

    QTextCursor cursor = document->rootFrame()->lastCursorPosition();
    cursor.movePosition(QTextCursor::StartOfBlock);

    QTextFrameFormat frameFormat;
    frameFormat.setPadding(4);
    frameFormat.setBackground(messageColor.lighter(190));
    frameFormat.setMargin(0);
    frameFormat.setBorder(2);
    frameFormat.setBorderBrush(messageColor.lighter(150));
    frameFormat.setBorderStyle(QTextFrameFormat::BorderStyle_Outset);

    // Title
    QTextCharFormat backupCharFormat = cursor.charFormat();

    QTextCharFormat newCharFormat;
    newCharFormat.setFontPointSize(9);

    QTextBlockFormat headerFormat;
    headerFormat.setAlignment(Qt::AlignHCenter);
    cursor.insertBlock(headerFormat);
    cursor.setCharFormat(newCharFormat);
    cursor.insertText(QDateTime::currentDateTime().toString());

    QTextFrame *frame = cursor.insertFrame(frameFormat);
    cursor.setCharFormat(backupCharFormat);
    frame->firstCursorPosition().insertText(message);

    return true;
}
开发者ID:pcjpnet,项目名称:qwired-suite,代码行数:38,代码来源:QwcPrivateMessager.cpp

示例3: createCSVImportView

void CSVImportDialog::createCSVImportView(QString filenamein)
{
    QFile file(filenamein);
    if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
        // read file
        ui->csvTextEdit->setText(file.readAll());
    }

    this->setWindowTitle("CSV Import - " + filenamein);

    QTextCursor cursor = ui->csvTextEdit->textCursor();
    QTextCharFormat format;

    cursor.select(QTextCursor::Document);
    format.setForeground( QBrush( QColor( "black" ) ) );
    format.setFontStrikeOut(false);
    cursor.setCharFormat( format );

    for(int i=0; i<ui->lineskipSpinBox->value(); i++){
        format.setForeground( QBrush( QColor( "red" ) ) );
        format.setFontStrikeOut(true);
        cursor.movePosition(QTextCursor::Start);
        cursor.movePosition(QTextCursor::Down, QTextCursor::MoveAnchor, i);
        cursor.select(QTextCursor::LineUnderCursor);
        cursor.setCharFormat( format );
    }

}
开发者ID:torlenor,项目名称:Costs,代码行数:28,代码来源:csvimportdialog.cpp

示例4: spellCheck

void TCommandLine::spellCheck()
{
    if (!mpHost->mEnableSpellCheck) {
        return;
    }

    QTextCursor oldCursor = textCursor();
    QTextCharFormat f;
    auto cred = QColor(Qt::red);
    f.setUnderlineStyle(QTextCharFormat::SpellCheckUnderline);
    f.setUnderlineColor(cred);
    QTextCursor c = textCursor();
    c.select(QTextCursor::WordUnderCursor);

    if (!Hunspell_spell(mpHunspell, c.selectedText().toLatin1().data())) {
        f.setFontUnderline(true);
        c.setCharFormat(f);
    } else {
        f.setFontUnderline(false);
        c.setCharFormat(f);
    }
    setTextCursor(c);
    f.setFontUnderline(false);
    oldCursor.setCharFormat(f);
    setTextCursor(oldCursor);
}
开发者ID:Mudlet,项目名称:Mudlet,代码行数:26,代码来源:TCommandLine.cpp

示例5: joinedChannel

void ChatTextEdit::joinedChannel(int channelid)
{
    TTCHAR buff[TT_STRLEN];
    Channel chan;
    if(!TT_GetChannel(ttInst, channelid, &chan))
        return;
    if(!TT_GetChannelPath(ttInst, channelid, buff))
        return;

    appendPlainText("");

    QString dt = getTimeStamp();
    
    QTextCharFormat format = textCursor().charFormat();
    QTextCharFormat original = format;
    QTextCursor cursor = textCursor();
    
    //show 'joined new channel' in bold
    QFont font = format.font();
    font.setBold(true);
    format.setFont(font);
    cursor.setCharFormat(format);
    QString line = dt + tr("Joined new channel");
    setTextCursor(cursor);
    appendPlainText(line);
    //revert bold
    font.setBold(false);
    format.setFont(font);
    
    //show channel name in green
    line = tr("Channel: %1").arg(_Q(buff));
    format.setForeground(QBrush(Qt::darkGreen));
    cursor.setCharFormat(format);
    setTextCursor(cursor);
    appendPlainText(line);

    //show topic in blue
    line = tr("Topic: %1").arg(_Q(chan.szTopic));
    format.setForeground(QBrush(Qt::darkBlue));
    cursor.setCharFormat(format);
    setTextCursor(cursor);
    appendPlainText(line);

    //show disk quota in red
    line = tr("Disk quota: %1 KBytes").arg(chan.nDiskQuota/1024);
    format.setForeground(QBrush(Qt::darkRed));
    cursor.setCharFormat(format);
    setTextCursor(cursor);
    appendPlainText(line);

    //revert to original
    cursor.setCharFormat(original);
    setTextCursor(cursor);
    limitText();
}
开发者ID:BearWare,项目名称:TeamTalk5,代码行数:55,代码来源:chattextedit.cpp

示例6: appendCardTag

void ChatView::appendCardTag(QTextCursor &cursor, const QString &cardName)
{
    QTextCharFormat oldFormat = cursor.charFormat();
    QTextCharFormat anchorFormat = oldFormat;
    anchorFormat.setForeground(Qt::blue);
    anchorFormat.setAnchor(true);
    anchorFormat.setAnchorHref("card://" + cardName);
    
    cursor.setCharFormat(anchorFormat);
    cursor.insertText(cardName);
    cursor.setCharFormat(oldFormat);
}
开发者ID:Akira586,项目名称:Cockatrice,代码行数:12,代码来源:chatview.cpp

示例7: addTextMessage

QString ChatTextEdit::addTextMessage(const TextMessage& msg)
{
    User user;
    if(!TT_GetUser(ttInst, msg.nFromUserID, &user))
        return QString();

    QString dt = getTimeStamp();
    QString line = dt;

    switch(msg.nMsgType)
    {
    case MSGTYPE_USER :
        line += QString("<%1> %2").arg(getDisplayName(user)).arg(_Q(msg.szMessage));
        break;
    case MSGTYPE_CHANNEL :
        if(msg.nChannelID != TT_GetMyChannelID(ttInst))
        {
            TTCHAR chpath[TT_STRLEN] = {};
            TT_GetChannelPath(ttInst, msg.nChannelID, chpath);
            line += QString("<%1->%2> %3").arg(getDisplayName(user))
                           .arg(_Q(chpath)).arg(_Q(msg.szMessage));
        }
        else
            line += QString("<%1> %2").arg(getDisplayName(user))
                           .arg(_Q(msg.szMessage));
        break;
    case MSGTYPE_BROADCAST :
        line += QString("<%1->BROADCAST> %2").arg(getDisplayName(user))
                       .arg(_Q(msg.szMessage));
        break;
    case MSGTYPE_CUSTOM : break;
    }

    if(TT_GetMyUserID(ttInst) == msg.nFromUserID)
    {
        QTextCharFormat format = textCursor().charFormat();
        QTextCharFormat original = format;
        format.setForeground(QBrush(Qt::darkGray));
        QTextCursor cursor = textCursor();
        cursor.setCharFormat(format);
        setTextCursor(cursor);
        appendPlainText(line);
        cursor.setCharFormat(original);
        setTextCursor(cursor);
    }
    else
        appendPlainText(line);
    limitText();

    return line;
}
开发者ID:BearWare,项目名称:TeamTalk5,代码行数:51,代码来源:chattextedit.cpp

示例8: addLogMessage

void ChatTextEdit::addLogMessage(const QString& msg)
{
    QString line = QString("%1 * %2").arg(getTimeStamp()).arg(msg);
    QTextCharFormat format = textCursor().charFormat();
    QTextCharFormat original = format;
    format.setForeground(QBrush(Qt::gray));
    QTextCursor cursor = textCursor();
    cursor.setCharFormat(format);
    setTextCursor(cursor);
    appendPlainText(line);
    cursor.setCharFormat(original);
    setTextCursor(cursor);
    limitText();
}
开发者ID:BearWare,项目名称:TeamTalk5,代码行数:14,代码来源:chattextedit.cpp

示例9: appendUrlTag

void ChatView::appendUrlTag(QTextCursor &cursor, QString url)
{
    if (!url.contains("://"))
        url.prepend("http://");
    
    QTextCharFormat oldFormat = cursor.charFormat();
    QTextCharFormat anchorFormat = oldFormat;
    anchorFormat.setForeground(Qt::blue);
    anchorFormat.setAnchor(true);
    anchorFormat.setAnchorHref(url);
    
    cursor.setCharFormat(anchorFormat);
    cursor.insertText(url);
    cursor.setCharFormat(oldFormat);
}
开发者ID:Akira586,项目名称:Cockatrice,代码行数:15,代码来源:chatview.cpp

示例10: appendText

void QTerminalEdit::appendText(QByteArray newText, bool internal)
{
    QTextCursor tc = this->textCursor();
    QTextCharFormat tcf = tc.charFormat();
    if(internal)
    {
        tcf.setForeground(QBrush(QColor("green")));
        tc.movePosition(QTextCursor::End);

        if(hexMode)
        {
            QString hexFormat;
            while(newText.size()>0)
            {
                QString temp = newText.left(1).toHex().toUpper();
                newText.remove(0,1);
                hexFormat.append(temp);
                hexFormat.append(" ");
                if(temp==QString("0D"))
                {
                    hexFormat.append('\n');
                }
            }

            tc.setCharFormat(tcf);
            tc.insertText(hexFormat);
            tc.movePosition(QTextCursor::End);
        }
        else
        {
            QString data;
            foreach(char ch, newText)
            {
                if(ch !=0)
                {
                    data.append(ch);
                }
            }

            tc.setCharFormat(tcf);
            tc.insertText(data);
            tc.movePosition(QTextCursor::End);

        }
        this->setTextCursor(tc);
    }
    else
    {
开发者ID:dasanchez,项目名称:QConnect,代码行数:48,代码来源:qterminaledit.cpp

示例11: setTextFont

// 设置字体格式
void MainWindow::setTextFont(bool checked)
{
    // 如果处于选中状态
    if(checked){
        QTextCursor cursor = ui->textEdit->textCursor();

        // 文本块格式
        QTextBlockFormat blockFormat;
        // 水平居中
        blockFormat.setAlignment(Qt::AlignCenter);
        // 使用文本块格式
        cursor.insertBlock(blockFormat);

        // 字符格式
        QTextCharFormat charFormat;
        // 背景色
        charFormat.setBackground(Qt::lightGray);
        // 字体颜色
        charFormat.setForeground(Qt::blue);
        // 使用宋体,12号,加粗,倾斜
        charFormat.setFont(QFont(tr("宋体"),12,QFont::Bold,true));

        // 使用下划线
        charFormat.setFontUnderline(true);
        // 使用字符格式
        cursor.setCharFormat(charFormat);
        // 插入文本
        cursor.insertText(tr("测试字体"));
    }
    // 如果处于非选中状态,可以进行其他操作
    else{/*恢复默认的字体格式*/}
}
开发者ID:Rookiee,项目名称:Qt_Codes,代码行数:33,代码来源:mainwindow.cpp

示例12: toggleStrikethroughText

void ItemEditorWidget::toggleStrikethroughText()
{
    QTextCursor tc = textCursor();
    QTextCharFormat format = tc.charFormat();
    format.setFontStrikeOut( !format.fontStrikeOut() );
    tc.setCharFormat(format);
}
开发者ID:amosbird,项目名称:CopyQ,代码行数:7,代码来源:itemeditorwidget.cpp

示例13: toggleItalicText

void ItemEditorWidget::toggleItalicText()
{
    QTextCursor tc = textCursor();
    QTextCharFormat format = tc.charFormat();
    format.setFontItalic( !format.fontItalic() );
    tc.setCharFormat(format);
}
开发者ID:amosbird,项目名称:CopyQ,代码行数:7,代码来源:itemeditorwidget.cpp

示例14: toggleUnderlineText

void ItemEditorWidget::toggleUnderlineText()
{
    QTextCursor tc = textCursor();
    QTextCharFormat format = tc.charFormat();
    format.setFontUnderline( !format.fontUnderline() );
    tc.setCharFormat(format);
}
开发者ID:amosbird,项目名称:CopyQ,代码行数:7,代码来源:itemeditorwidget.cpp

示例15: formatError

QT_BEGIN_NAMESPACE

static void formatError(const QFormScriptRunner::Error &error,
                        QTextCursor &cursor)
{
    const QTextCharFormat oldFormat = cursor.charFormat();
    // Message
    cursor.insertText(QCoreApplication::translate("ScriptErrorDialog", "An error occurred while running the scripts for \"%1\":\n").arg(error.objectName));

    QTextCharFormat format(oldFormat);

    // verbatim listing
    format.setFontFamily(QLatin1String("Courier"));
    cursor.insertText(error.script, format);

    const QString newLine(QLatin1Char('\n'));

    cursor.insertText(newLine);

    // red error
    format = oldFormat;
    format.setTextOutline(QPen(Qt::red));
    cursor.insertText(error.errorMessage, format);
    cursor.insertText(newLine);
    cursor.setCharFormat (oldFormat);
}
开发者ID:kuailexs,项目名称:symbiandump-mw3,代码行数:26,代码来源:scripterrordialog.cpp


注:本文中的QTextCursor::setCharFormat方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。