本文整理汇总了C++中QTextEdit::toHtml方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextEdit::toHtml方法的具体用法?C++ QTextEdit::toHtml怎么用?C++ QTextEdit::toHtml使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextEdit
的用法示例。
在下文中一共展示了QTextEdit::toHtml方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: editTextClicked
void EditStyle::editTextClicked(int id)
{
QTextEdit* e = 0;
switch (id) {
case 0: e = evenHeaderL; break;
case 1: e = evenHeaderC; break;
case 2: e = evenHeaderR; break;
case 3: e = oddHeaderL; break;
case 4: e = oddHeaderC; break;
case 5: e = oddHeaderR; break;
case 6: e = evenFooterL; break;
case 7: e = evenFooterC; break;
case 8: e = evenFooterR; break;
case 9: e = oddFooterL; break;
case 10: e = oddFooterC; break;
case 11: e = oddFooterR; break;
}
if (e == 0)
return;
bool styled = id < 6 ? headerStyled->isChecked() : footerStyled->isChecked();
if (styled)
e->setPlainText(editPlainText(e->toPlainText(), tr("Edit Plain Text")));
else
e->setHtml(editHtml(e->toHtml(), tr("Edit HTML Text")));
}
示例2: on_btn_kopiraj_clicked
void wid_stranke::on_btn_kopiraj_clicked() {
QClipboard *odlozisce = QApplication::clipboard();
QModelIndexList selectedList = ui->tbl_stranke->selectionModel()->selectedRows();
QString html_besedilo = "<table>";
html_besedilo += "<tr>";
html_besedilo += "<th>ID</th>";
html_besedilo += "<th>Ime/Naziv</th>";
html_besedilo += "<th>Priimek/Polni naziv</th>";
html_besedilo += "<th>Telefon</th>";
html_besedilo += "<th>GSM</th>";
html_besedilo += "<th>Elektronski naslov</th>";
html_besedilo += "<th>Izobrazevalna ustanova</th>";
html_besedilo += "<th>Tip stranke</th>";
html_besedilo += "</tr>";
for( int i = 0; i < selectedList.count(); i++) {
html_besedilo += "<tr>";
for ( int a = 0; a < 8; a++ ) {
html_besedilo += "<td>";
html_besedilo += ui->tbl_stranke->item(selectedList.at(i).row(), a)->text();
html_besedilo += "</td>";
}
html_besedilo += "</tr>";
}
html_besedilo += "</table>";
QTextEdit *textedit = new QTextEdit;
textedit->setHtml(html_besedilo);
html_besedilo = textedit->toHtml();
odlozisce->clear();
QMimeData *mimeData = new QMimeData();
mimeData->setData("text/html", html_besedilo.toUtf8());
odlozisce->setMimeData(mimeData, QClipboard::Clipboard);
}
示例3: sendChat
void PopupChatDialog::sendChat()
{
QTextEdit *chatWidget = ui.chattextEdit;
ChatInfo ci;
{
rsiface->lockData(); /* Lock Interface */
const RsConfig &conf = rsiface->getConfig();
ci.rsid = conf.ownId;
ci.name = conf.ownName;
rsiface->unlockData(); /* Unlock Interface */
}
ci.msg = chatWidget->toHtml().toStdWString();
ci.chatflags = RS_CHAT_PRIVATE;
#ifdef CHAT_DEBUG
std::cout << "PopupChatDialog:sendChat " << styleHtm.toStdString() << std::endl;
#endif
addChatMsg(&ci);
/* put proper destination */
ci.rsid = dialogId;
ci.name = dialogName;
rsMsgs -> ChatSend(ci);
chatWidget ->clear();
setFont();
/* redraw send list */
}
示例4: editTextClicked
void EditStyle::editTextClicked(int id)
{
QTextEdit* e = 0;
switch (id) {
case 0: e = evenHeaderL; break;
case 1: e = evenHeaderC; break;
case 2: e = evenHeaderR; break;
case 3: e = oddHeaderL; break;
case 4: e = oddHeaderC; break;
case 5: e = oddHeaderR; break;
case 6: e = evenFooterL; break;
case 7: e = evenFooterC; break;
case 8: e = evenFooterR; break;
case 9: e = oddFooterL; break;
case 10: e = oddFooterC; break;
case 11: e = oddFooterR; break;
}
if (e == 0)
return;
e->setHtml(editHtml(e->toHtml(), tr("Edit HTML Text")));
}
示例5: sendMsg
void PeersDialog::sendMsg()
{
QTextEdit *lineWidget = ui.lineEdit;
ChatInfo ci;
//ci.msg = lineWidget->Text().toStdWString();
ci.msg = lineWidget->toHtml().toStdWString();
ci.chatflags = RS_CHAT_PUBLIC;
//historyKeeper.addMessage("THIS", "ALL", lineWidget->toHtml() );
std::string msg(ci.msg.begin(), ci.msg.end());
#ifdef PEERS_DEBUG
std::cerr << "PeersDialog::sendMsg(): " << msg << std::endl;
#endif
rsMsgs -> ChatSend(ci);
ui.lineEdit->clear();
setFont();
/* redraw send list */
insertSendList();
}
示例6: insertFromMimeData
void TextZone::insertFromMimeData (const QMimeData *source )
{
QTextCursor cursor = this->textCursor();
int bottMargin;
int textIndent;
int leftMargin;
Qt::Alignment textAlignment;
int textHeight;
QString fontFamily;
if(cursor.atStart() == true
|| cursor.position() == 1
|| cursor.position() == 0){
int defaultIndex = textStyles->defaultStyleIndex();
bottMargin = textStyles->blockBottomMarginAt(defaultIndex);
textIndent = textStyles->blockFirstLineIndentAt(defaultIndex);
leftMargin = textStyles->blockLeftMarginAt(defaultIndex);
textAlignment = textStyles->blockAlignmentTrueNameAt(defaultIndex);
textHeight = textStyles->fontSizeAt(defaultIndex);
fontFamily = textStyles->fontFamilyAt(defaultIndex);
}
else{
bottMargin = cursor.blockFormat().bottomMargin();
textIndent = cursor.blockFormat().textIndent();
leftMargin = cursor.blockFormat().leftMargin();
textAlignment = cursor.blockFormat().alignment();
textHeight = cursor.charFormat().fontPointSize();
fontFamily = cursor.charFormat().fontFamily();
}
if(source->hasHtml() && !forceCopyWithoutFormatting){
QByteArray richtext;
if (source->hasFormat(QLatin1String("text/rtf"))) {
richtext = source->data(QLatin1String("text/rtf"));
} else if (source->hasHtml()) {
richtext = mimeToRtf(source);
}
QTextEdit *textEdit = new QTextEdit(0);
RTF::Reader reader;
QBuffer buffer(&richtext);
buffer.open(QIODevice::ReadOnly);
reader.read(&buffer, textEdit->textCursor());
buffer.close();
QString sourceString = textEdit->toHtml();
sourceString.remove(QChar::ReplacementCharacter);
sourceString.remove(QChar::ObjectReplacementCharacter);
sourceString.remove(QChar::Null);
//htmlText
QTextDocument *document = new QTextDocument;
document->setHtml(Utils::parseHtmlText(sourceString));
QTextBlockFormat blockFormat;
blockFormat.setBottomMargin(bottMargin);
blockFormat.setTextIndent(textIndent);
blockFormat.setLeftMargin(leftMargin);
blockFormat.setAlignment(textAlignment);
blockFormat.setRightMargin(0);
QTextCharFormat charFormat;
charFormat.setFontPointSize(textHeight);
charFormat.setFontFamily(fontFamily);
charFormat.setBackground(QBrush(Qt::NoBrush));
charFormat.setForeground(QBrush(Qt::NoBrush));
charFormat.setAnchor(false);
charFormat.setUnderlineStyle(QTextCharFormat::NoUnderline);
charFormat.setFontStrikeOut(false);
QTextCursor *tCursor = new QTextCursor(document);
tCursor->movePosition(QTextCursor::Start, QTextCursor::MoveAnchor,1);
tCursor->movePosition(QTextCursor::End, QTextCursor::KeepAnchor,1);
tCursor->mergeCharFormat(charFormat);
tCursor->mergeBlockFormat(blockFormat);
QTextCursor cursor = this->textCursor();
cursor.insertHtml(document->toHtml("utf-8"));
qDebug() << "insertFromMimeData Html";
}
else if(source->hasText() || forceCopyWithoutFormatting){
QTextDocument *document = new QTextDocument;
document->setPlainText(qvariant_cast<QString>(source->text()));
QTextBlockFormat blockFormat;
blockFormat.setBottomMargin(bottMargin);
blockFormat.setTextIndent(textIndent);
blockFormat.setLeftMargin(leftMargin);
blockFormat.setAlignment(textAlignment);
blockFormat.setRightMargin(0);
QTextCharFormat charFormat;
//.........这里部分代码省略.........
示例7: toHtml
int TextEdit::toHtml(lua_State * L) // const : QString
{
QTextEdit* obj = ObjectHelper<QTextEdit>::check( L, 1);
lua_pushstring(L, obj->toHtml().toLatin1() );
return 1;
}
示例8: retrieveValue
bool QgsAttributeEditor::retrieveValue( QWidget *widget, QgsVectorLayer *vl, int idx, QVariant &value )
{
if ( !widget )
return false;
const QgsField &theField = vl->pendingFields()[idx];
QgsVectorLayer::EditType editType = vl->editType( idx );
bool modified = false;
QString text;
QSettings settings;
QString nullValue = settings.value( "qgis/nullValue", "NULL" ).toString();
QLineEdit *le = qobject_cast<QLineEdit *>( widget );
if ( le )
{
text = le->text();
modified = le->isModified();
if ( text == nullValue )
{
text = QString::null;
}
}
QTextEdit *te = qobject_cast<QTextEdit *>( widget );
if ( te )
{
text = te->toHtml();
modified = te->document()->isModified();
if ( text == nullValue )
{
text = QString::null;
}
}
QPlainTextEdit *pte = qobject_cast<QPlainTextEdit *>( widget );
if ( pte )
{
text = pte->toPlainText();
modified = pte->document()->isModified();
if ( text == nullValue )
{
text = QString::null;
}
}
QComboBox *cb = qobject_cast<QComboBox *>( widget );
if ( cb )
{
if ( editType == QgsVectorLayer::UniqueValues ||
editType == QgsVectorLayer::ValueMap ||
editType == QgsVectorLayer::Classification ||
editType == QgsVectorLayer::ValueRelation )
{
text = cb->itemData( cb->currentIndex() ).toString();
if ( text == nullValue )
{
text = QString::null;
}
}
else
{
text = cb->currentText();
}
modified = true;
}
QListWidget *lw = qobject_cast<QListWidget *>( widget );
if ( lw )
{
if ( editType == QgsVectorLayer::ValueRelation )
{
text = '{';
for ( int i = 0, n = 0; i < lw->count(); i++ )
{
if ( lw->item( i )->checkState() == Qt::Checked )
{
if ( n > 0 )
{
text.append( ',' );
}
text.append( lw->item( i )->data( Qt::UserRole ).toString() );
n++;
}
}
text.append( '}' );
}
else
{
text = QString::null;
}
modified = true;
}
QSpinBox *sb = qobject_cast<QSpinBox *>( widget );
if ( sb )
{
text = QString::number( sb->value() );
}
//.........这里部分代码省略.........
示例9: insertChat
void PeersDialog::insertChat()
{
if (!rsMsgs->chatAvailable())
{
// std::cerr << "no chat available." << std::endl ;
return;
}
std::list<ChatInfo> newchat;
if (!rsMsgs->getNewChat(newchat))
{
std::cerr << "could not get new chat." << std::endl ;
return;
}
std::cerr << "got new chat." << std::endl ;
QTextEdit *msgWidget = ui.msgText;
std::list<ChatInfo>::iterator it;
/** A RshareSettings object used for saving/loading settings */
RshareSettings settings;
uint chatflags = settings.getChatFlags();
/* add in lines at the bottom */
for(it = newchat.begin(); it != newchat.end(); it++)
{
std::string msg(it->msg.begin(), it->msg.end());
#ifdef PEERS_DEBUG
std::cerr << "PeersDialog::insertChat(): " << msg << std::endl;
#endif
/* are they private? */
if (it->chatflags & RS_CHAT_PRIVATE)
{
PopupChatDialog *pcd = getPrivateChat(it->rsid, it->name, chatflags);
pcd->addChatMsg(&(*it));
continue;
}
std::ostringstream out;
QString currenttxt = msgWidget->toHtml();
QString extraTxt;
QString timestamp = QDateTime::currentDateTime().toString("hh:mm:ss");
QString name = QString::fromStdString(it->name);
QString line = "<span style=\"color:#C00000\">" + timestamp + "</span>" +
"<span style=\"color:#2D84C9\"><strong>" + " " + name + "</strong></span>";
//std::cerr << "PeersDialog::insertChat(): 1.11\n";
historyKeeper.addMessage(name, "THIS", QString::fromStdWString(it->msg));
//std::cerr << "PeersDialog::insertChat(): 1.12\n";
extraTxt += line;
extraTxt += QString::fromStdWString(it->msg);
/* add it everytime */
currenttxt += extraTxt;
QHashIterator<QString, QString> i(smileys);
while(i.hasNext())
{
i.next();
foreach(QString code, i.key().split("|"))
currenttxt.replace(code, "<img src=\"" + i.value() + "\" />");
}
msgWidget->setHtml(currenttxt);
QScrollBar *qsb = msgWidget->verticalScrollBar();
qsb -> setValue(qsb->maximum());
}
}