本文整理汇总了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>"));
}
}
}
示例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);
}
示例3: setVisible
void NotesWindow::setVisible(bool visible)
{
if (ui->textEdit->document()->isEmpty()) {
qSort(m_notes);
QTextCursor cursor = ui->textEdit->textCursor();
foreach (const NoteText ¬e, 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());
}
示例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());
}
示例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 );
}
示例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" ) );
}
示例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();
}
示例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);
}
示例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();
}
示例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);
}
示例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;
}
示例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("<","<");
c.replace(">",">");
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);
}
示例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());
}
示例14: rx
void dlgIRC::irc_gotMsg2( QString a, QStringList c )
{
QString m = c.join(" ");
m.replace("<","<");
m.replace(">",">");
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);
}
示例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);
}
}