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


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

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


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

示例1: displayTooltip

void MainWindow::displayTooltip(QMouseEvent *e)
{
    static bool isFirstTime = true;
    static int selectionStart;
    static QString selectedText;
    static bool isExisted = false; //мы выделяли существующее в словаре?
    bool isExist = false;
    int i;

    QPoint p = e->pos();

    QTextCursor tc = ui->textEdit->cursorForPosition(p);
    tc.select(QTextCursor::WordUnderCursor);

    if (selectionStart != tc.selectionStart()) {

        //проверяем, есть ли слово в словаре
        for(i = 0; i < bptr->getListWords().size(); i++)
        {
            if(!bptr->getListWords().at(i).word.compare(tc.selectedText(), Qt::CaseInsensitive))
            {
                isExist = true;
                break;
            }
            if(!bptr->getListWords().at(i).word.compare(selectedText, Qt::CaseInsensitive))
            {
                isExisted = true;
            }
        }

        if (!isFirstTime)
        {
            QToolTip::hideText();   //скрываем предыдущий тултип
            //Надо удалить выделение предыдущего слова
            QTextCursor tc(ui->textEdit->document());
            tc.setPosition(selectionStart);
            tc.select(QTextCursor::WordUnderCursor);

            if(isExisted)
                tc.insertHtml(QString("<u>" + selectedText + "</b>"));
            else
            {
                tc.insertHtml(QString(selectedText));
            }
            isExisted = false;
        }
        selectionStart = tc.selectionStart();
        selectedText = tc.selectedText();

        if (tc.selectedText().length() > 0 && isExist)
        {
//            QToolTip::showText(e->globalPos(), bptr->getListWords().at(i).toString(),
//                               ui->textEdit, ui->textEdit->cursorRect());
            QToolTip::showText(e->globalPos(), bptr->getListWords().at(i).toString(),
                               ui->textEdit, ui->textEdit->cursorRect(tc));
            isFirstTime = false;
            tc.insertHtml(QString("<b>" + tc.selectedText() + "</b>"));
        }
    }
}
开发者ID:maharajd,项目名称:BookReader,代码行数:60,代码来源:mainwindow.cpp

示例2: addLink

void DocBlock::addLink(QUrl url)
{
    myTextItem->setTextInteractionFlags(Qt::TextSelectableByKeyboard);
    docType = Link;
    path = url.toString();
    QString str = path;

    // add file icon
    QTextCursor cursor = QTextCursor(myTextItem->document());
    QFileInfo info(url.toLocalFile());
    QFileIconProvider *provider = new QFileIconProvider();
    QImage image(provider->icon(info).pixmap(16, 16).toImage());
    cursor.document()->setPlainText(" ");
    cursor.insertImage(image);
	
    if (str.lastIndexOf("/") > -1)
        str = str.right(str.size() - str.lastIndexOf("/") - 1);

    QString html = "<a href=\""+path+"\">"+str+"</a>";
    cursor.insertHtml(html);
	
    if (arrow != 0) arrow->setColor(getHoverColor());

    updateBlock(false);
}
开发者ID:fejo,项目名称:TrollEdit-1,代码行数:25,代码来源:doc_block.cpp

示例3: setVisible

void NotesWindow::setVisible(bool visible)
{
    if (ui->textEdit->document()->isEmpty()) {
        qSort(m_notes);
        QTextCursor cursor = ui->textEdit->textCursor();
        foreach (const NoteText &note, m_notes) {
            //cursor.insertText(s_separator);
            cursor.insertHtml(QStringLiteral("<hr>"));
            cursor.insertBlock();
            cursor.setBlockFormat(QTextBlockFormat());
            cursor.insertHtml(note.htmlHeader());
            cursor.setBlockFormat(QTextBlockFormat());
            cursor.insertBlock();
            cursor.insertBlock();
            if (note.isHtml())
                cursor.insertHtml(note.text());
            else
                cursor.insertText(note.text());
        }
开发者ID:KDAB,项目名称:FatCRM,代码行数:19,代码来源:noteswindow.cpp

示例4: on_insertHtml_clicked

void MainWindow::on_insertHtml_clicked()
{
    QTextEdit *pEdit = textEditor.editor;
    QTextCursor cursor = pEdit->textCursor();

    InsertHtmlDialog dlg(this);
    if(dlg.exec() != QDialog::Accepted)
        return;
    cursor.insertHtml(dlg.htmlText());
}
开发者ID:KanagiMiss,项目名称:testassist,代码行数:10,代码来源:mainwindow.cpp

示例5: slot_joined

void dlgIRC::slot_joined(QString nick, QString chan )
{
    const QString _t = QTime::currentTime().toString();
    QString t = tr("<font color=#008800>[%1] %2 has joined the channel.</font>").arg(_t).arg(nick);
    QTextCursor cur = irc->textCursor();
    cur.movePosition(QTextCursor::End);
    cur.insertBlock();
    cur.insertHtml(t);
    irc->verticalScrollBar()->triggerAction(QScrollBar::SliderToMaximum);
    nickList->addItem( nick );
}
开发者ID:EldFitheach,项目名称:Mudlet,代码行数:11,代码来源:dlgIRC.cpp

示例6: slot_parted

void dlgIRC::slot_parted(QString nick, QString chan, QString msg )
{
    const QString _t = QTime::currentTime().toString();
    QString t = tr("<font color=#888800>[%1] %2 has left the channel.</font>").arg(_t).arg(nick);
    QTextCursor cur = irc->textCursor();
    cur.movePosition(QTextCursor::End);
    cur.insertBlock();
    cur.insertHtml(t);
    irc->verticalScrollBar()->triggerAction(QScrollBar::SliderToMaximum);
    nickList->clear();
    session->sendCommand( IrcCommand::createNames( "#mudlet" ) );
}
开发者ID:EldFitheach,项目名称:Mudlet,代码行数:12,代码来源:dlgIRC.cpp

示例7: addEmoji

void ChatTextEdit::addEmoji(QString emojiName)
{
    if (isEmojiWidgetOpen && Client::autoCloseEmoji)
        closeEmojiWidget();

    QTextCursor cursor = textCursor();

    QString html = "<img src=\"/usr/share/yappari/icons/32x32/" + emojiName +".png\" />";

    cursor.insertHtml(html);
    setFocus();
}
开发者ID:0xaaa,项目名称:yappari,代码行数:12,代码来源:chattextedit.cpp

示例8: _insertText

void DisplayText::_insertText(const QString text, const QString bg)
{
    QString tt = text.mid(0,_maxDisplayedCharacters); //truncate to max display chars
    QString s = "<table border=0 cellspacing=0 width=100%><tr><td bgcolor=\"" +
                bg + "\"><pre>" + tt + "</pre></td></tr></table>";

    QTextCursor cursor = textCursor();
    cursor.movePosition(QTextCursor::End);
    QTextBlockFormat bf = cursor.blockFormat();
    bf.setBackground(QBrush(QColor(bg)));
    cursor.insertHtml(s);
    this->setTextCursor(cursor);
}
开发者ID:BackupTheBerlios,项目名称:wsjt-svn,代码行数:13,代码来源:displaytext.cpp

示例9: setHtml

void ChatMessageArea::setHtml(const QString& html) {
    // Create format with updated line height
    QTextBlockFormat format;
    format.setLineHeight(CHAT_MESSAGE_LINE_HEIGHT, QTextBlockFormat::ProportionalHeight);

    // Possibly a bug in QT, the format won't take effect if `insertHtml` is used first.  Inserting a space and deleting
    // it after ensures the format is applied.
    QTextCursor cursor = textCursor();
    cursor.setBlockFormat(format);
    cursor.insertText(" ");
    cursor.insertHtml(html);
    cursor.setPosition(0);
    cursor.deleteChar();
}
开发者ID:Adrianl3d,项目名称:hifi,代码行数:14,代码来源:ChatMessageArea.cpp

示例10: setText

void GroupItem::setText()
{
    document()->clear();
    prepareGeometryChange();
    QTextCursor cursor = textCursor();
    cursor.movePosition (QTextCursor::End);
    // TODO add style sheet
    QString html = "<div id='GroupItem'>" +
                   QString::fromUtf8 (groupName) + "</div>";
    if (not showChildItems)
    {
        html.append ("<span id='itemCount'> (" +
                     QString::number (childItems().size()) + ")</span>");
    }
    cursor.insertHtml (html);
    setTextCursor (cursor);
}
开发者ID:lyarbean,项目名称:Bressein,代码行数:17,代码来源:groupitem.cpp

示例11: hacerInforme

/*!
    \fn IRenderizador::hacerInforme()
 */
void IRenderizador::hacerInforme()
{
 QTextCursor *cursor = new QTextCursor( _doc );
 cursor->movePosition( QTextCursor::End );
 // cargar la cabecera
 cursor->insertHtml( cargarCabecera() );
 // Pongo la fecha del informe
 cursor->insertText( QString( "Fecha: %1.\n" ).arg( QDate::currentDate().toString( "dd/MM/yyyy" ) ) );
 // Establecimiento en cuestion
 QSqlQuery *colaAuxiliar = new QSqlQuery();
 colaAuxiliar->exec( QString("SELECT nombre FROM car_establecimientos WHERE id_establecimiento = '%1'").arg( _idEstablecimiento ) );
 if( colaAuxiliar->next() )
 {
 	cursor->insertText( QString( "Establecimiento:  %1\n" ).arg( colaAuxiliar->record().value(0).toString() ) );
 }
 else
 { qDebug( "Error al ejecutar la cola de nombre de establecimiento" ); }
 // Busco las caravanas que estan en ese establecimiento
 colaAuxiliar->exec( QString( "SELECT codigo FROM car_caravana WHERE id_caravana IN (  SELECT id_caravana FROM car_carv_tri WHERE id_tri IN (  SELECT id_tri FROM car_tri WHERE ( id_estab_origen = '%1' OR id_estab_destino = '%1' ) AND razon IN ( 2, 3 ) ) )" ).arg( _idEstablecimiento ) );
 if( colaAuxiliar->size() == 0 )
 {
   cursor->movePosition( QTextCursor::End );
   cursor->insertText( "\n\nNo existen resultados" );
 }
 else
 {
	// Genero la tabla
	cursor->movePosition( QTextCursor::End );
	tabla = cursor->insertTable( 1, 2 );
	QTextTableFormat formatoTabla = tabla->format();
	formatoTabla.setHeaderRowCount(1);
	tabla->setFormat( formatoTabla );
	tabla->cellAt( 0,0 ).firstCursorPosition().insertHtml( "#Num" );
	tabla->cellAt( 0,1 ).firstCursorPosition().insertHtml( "#Caravana" );
	while( colaAuxiliar->next() )
	{
		int pos = tabla->rows();
		tabla->insertRows( pos, 1 );
		tabla->cellAt( pos, 0 ).firstCursorPosition().insertHtml( QString( "%L1" ).arg( pos ) );
		tabla->cellAt( pos, 1 ).firstCursorPosition().insertHtml( colaAuxiliar->record().value(0).toString() );
	}
 } // fin else cola != 0
 delete colaAuxiliar;
 delete cursor;
 return;
}
开发者ID:chungote,项目名称:gestotux,代码行数:49,代码来源:irenderizador.cpp

示例12: irc_gotMsg

void dlgIRC::irc_gotMsg( QString a, QString b, QString c )
{
    qDebug()<<"a<"<<a<<"> b<"<<b<<">"<<" c<"<<c<<">";
    mudlet::self()->getHostManager()->postIrcMessage( a, b, c );
    c.replace("<","&#60;");
    c.replace(">","&#62;");
    const QString _t = QTime::currentTime().toString();

    QRegExp rx("(http://[^ ]*)");
    QStringList list;
    int pos = 0;

    while( (pos = rx.indexIn(c, pos)) != -1)
    {
        QString _l = "<a href=";
        _l.append( rx.cap(1) );
        _l.append(" >");
        c.insert(pos,_l);
        pos += (rx.matchedLength()*2)+9;
        c.insert(pos,"< /a>");
        pos += 5;
    }

    const QString msg = c;
    const QString n = a;
    QString t;
    if( b == mNick )
        t = tr("<font color=#a5a5a5>[%1] </font>msg from <font color=#ff0000>%2</font><font color=#ff0000>: %3</font>").arg(_t).arg(n).arg(msg);
    else if( a == mNick )
        t = tr("<font color=#a5a5a5>[%1] </font><font color=#00aaaa>%2</font><font color=#004400>: %3</font>").arg(_t).arg(n).arg(msg);
    else
        t = tr("<font color=#a5a5a5>[%1] </font><font color=#0000ff>%2</font><font color=#000000>: %3</font>").arg(_t).arg(n).arg(msg);


    QString hi = QString("<font color=#aa00aa>%1</font>").arg(mNick);
    t.replace(mNick, hi);
    QTextCursor cur = irc->textCursor();
    cur.movePosition(QTextCursor::End);
    cur.insertBlock();
    cur.insertHtml(t);
    irc->verticalScrollBar()->triggerAction(QScrollBar::SliderToMaximum);
}
开发者ID:EldFitheach,项目名称:Mudlet,代码行数:42,代码来源:dlgIRC.cpp

示例13: appendToLog

void ConsoleLog::appendToLog(QString message)
{
    bool scrollToBottom = false;

    if(_log->verticalScrollBar()->value() == _log->verticalScrollBar()->maximum())
    {
        scrollToBottom = true;
    }

    QTextBlockFormat format;
    format.setLineHeight(30, 0);

    QTextCursor cursor = _log->textCursor();
    cursor.setBlockFormat(format);
    int pos = cursor.position();
    cursor.setPosition(_log->toPlainText().length());
    cursor.insertHtml(message + "<br/><br/><br/>");
    cursor.setPosition(pos);

    if(scrollToBottom) _log->verticalScrollBar()->setValue(_log->verticalScrollBar()->maximum());
}
开发者ID:NunyoEffinBusiness,项目名称:Pandemic,代码行数:21,代码来源:consolelog.cpp

示例14: rx

void dlgIRC::irc_gotMsg2( QString a, QStringList c )
{
    QString m = c.join(" ");
    m.replace("<","&#60;");
    m.replace(">","&#62;");
    const QString _t = QTime::currentTime().toString();

    QRegExp rx("(http://[^ ]*)");
    QStringList list;

    int pos = 0;

    while( (pos = rx.indexIn(m, pos)) != -1)
    {
        QString _l = "<a href=";
        _l.append( rx.cap(1) );
        _l.append(" >");
        m.insert(pos,_l);
        pos += (rx.matchedLength()*2)+9;
        m.insert(pos,"< /a>");
        pos += 5;
    }

    const QString msg = m;
    const QString n = a;
    QString t;
    if( msg.contains( mNick ) )
        t = tr("<font color=#a5a5a5>[%1] </font><font color=#ff0000>%2</font><font color=#000000>: %3</font>").arg(_t).arg(n).arg(msg);
    else
        t = tr("<font color=#a5a5a5>[%1] </font><font color=#0000ff>%2</font><font color=#000000>: %3</font>").arg(_t).arg(n).arg(msg);

    //QString t = tr("<font color=#aaaaaa>[%1] </font><font color=#ff0000>%2</font><font color=#000000>: %3</font>").arg(_t).arg(n).arg(msg);
    QTextCursor cur = irc->textCursor();
    cur.movePosition(QTextCursor::End);
    cur.insertBlock();
    cur.insertHtml(t);
    irc->verticalScrollBar()->triggerAction(QScrollBar::SliderToMaximum);
}
开发者ID:EldFitheach,项目名称:Mudlet,代码行数:38,代码来源:dlgIRC.cpp

示例15: updateFromResult

ResultItem* TextResultItem::updateFromResult(Cantor::Result* result)
{
    switch(result->type()) {
    case Cantor::TextResult::Type:
        {
            QTextCursor cursor = textCursor();
            cursor.movePosition(QTextCursor::Start);
            cursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
            QString html = result->toHtml();
            if (html.isEmpty())
                cursor.removeSelectedText();
            else
                cursor.insertHtml(html);
            return this;
        }
    case Cantor::LatexResult::Type:
        setLatex(dynamic_cast<Cantor::LatexResult*>(result));
        return this;
    default:
        deleteLater();
        return create(parentEntry(), result);
    }
}
开发者ID:KDE,项目名称:cantor,代码行数:23,代码来源:textresultitem.cpp


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