本文整理汇总了C++中QTextCursor::mergeCharFormat方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextCursor::mergeCharFormat方法的具体用法?C++ QTextCursor::mergeCharFormat怎么用?C++ QTextCursor::mergeCharFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextCursor
的用法示例。
在下文中一共展示了QTextCursor::mergeCharFormat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updateCustomTextColor
/*!
This slot applies custom text color for user - entered text
It does not affect the text originally inserted into editor
*/
void NmEditorTextEdit::updateCustomTextColor()
{
NM_FUNCTION;
if (mCustomTextColor.first) {
QTextCursor tcursor = textCursor();
QTextCharFormat fmt;
int pos = tcursor.position();
if (pos > 0) {
// If there isn't any user-made selection - apply custom color
if (!tcursor.hasSelection() && !tcursor.hasComplexSelection()) {
// Select last added char and set its color to custom
if (tcursor.movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor, 1)
&& tcursor.hasSelection()) {
fmt = tcursor.charFormat();
fmt.setForeground(mCustomTextColor.second);
tcursor.mergeCharFormat(fmt);
}
}
}
else {
fmt = tcursor.charFormat();
fmt.setForeground(mCustomTextColor.second);
tcursor.mergeCharFormat(fmt);
setTextCursor(tcursor);
}
}
}
示例2: markCurrentLocation
void OCamlSource::markCurrentLocation()
{
timer_index++;
if ( _start_char != 0 && _end_char != 0 )
{
if ( timer_index < nb_timer_values )
{ // blink
QTextCharFormat selectedFormat;
QColor outlineColor;
if ( timer_index % 2 == 0 )
outlineColor = QColor( Qt::darkYellow );
else
outlineColor = QColor( Qt::yellow );
selectedFormat.setBackground( outlineColor );
QTextCursor cur = textCursor();
cur.movePosition( QTextCursor::Start, QTextCursor::MoveAnchor );
cur.movePosition( QTextCursor::NextCharacter, QTextCursor::MoveAnchor, _start_char );
cur.movePosition( QTextCursor::NextCharacter, QTextCursor::KeepAnchor, _end_char - _start_char );
cur.mergeCharFormat( selectedFormat );
}
else
{
QColor currentPositionColor = QColor( Qt::darkYellow );
QColor currentInstructionColor = QColor( Qt::yellow );
QTextCharFormat currentPositionFormat;
currentPositionFormat.setBackground( currentPositionColor );
QTextCharFormat currentInstructionFormat;
currentInstructionFormat.setBackground( currentInstructionColor );
QTextCursor cur = textCursor();
cur.movePosition( QTextCursor::Start, QTextCursor::MoveAnchor );
cur.movePosition( QTextCursor::NextCharacter, QTextCursor::MoveAnchor, _start_char );
cur.movePosition( QTextCursor::NextCharacter, QTextCursor::KeepAnchor, _end_char - _start_char );
cur.mergeCharFormat( currentInstructionFormat );
int current_position ;
if (_after)
current_position = _end_char - 1;
else
current_position = _start_char;
cur.movePosition( QTextCursor::Start, QTextCursor::MoveAnchor );
cur.movePosition( QTextCursor::NextCharacter, QTextCursor::MoveAnchor, current_position );
cur.movePosition( QTextCursor::NextCharacter, QTextCursor::KeepAnchor );
cur.mergeCharFormat( currentPositionFormat );
}
}
if ( timer_index < nb_timer_values )
{
markCurrentLocationTimer->setInterval( timer_values[ timer_index % nb_timer_values ] );
markCurrentLocationTimer->start();
}
}
示例3: attach
void KoTextInlineRdf::attach(KoTextInlineRdf *inlineRdf, QTextCursor &cursor)
{
QTextCharFormat format = cursor.charFormat();
QVariant v = QVariant::fromValue(inlineRdf);
format.setProperty(KoCharacterStyle::InlineRdf, v);
cursor.mergeCharFormat(format);
}
示例4: iniFontSize
//init font size
void TextEdit::iniFontSize(){
//the document contains 50 lines
cout<<"#textedit::inifontsize";
QString s="12";
qreal pointSize = s.toFloat();
QTextCharFormat fmt;
fmt.setFontPointSize(pointSize);
//QColor col = Qt::red;
//fmt.setForeground(col);
///textEdit->setCurrentCharFormat(fmt);
//cursor is the main widget which handle document editing
QTextCursor cursor = textEdit->textCursor();
//cursor.setPosition(120,QTextCursor::MoveAnchor);
//cursor.movePosition(QTextCursor::NoMove,QTextCursor::KeepAnchor,100000);//textEdit->document().length());
////mergeFormatOnWordOrSelection(fmt);
//cursor has four selection type: the last one select the entire document
cursor.select(QTextCursor::Document);
cursor.mergeCharFormat(fmt);
// QTextBlock block=cursor.block();
// cout<<"TextEdit.initFontSize:the block start and length:";
// cout<<block.position()<<","<<block.length();
// cout<<"TextEdit.initFontSize:the block text:"<<block.text();
//cursor.setPosition(0);
}
示例5: setUnderline
/*!
* \brief Changes the underline attribute of the selected text to \a v
*/
void QwwRichTextEdit::setUnderline(bool v){
QTextCursor cur = textCursor();
QTextCharFormat fmt;
fmt.setFontUnderline(v);
cur.mergeCharFormat(fmt);
setTextCursor(cur);
}
示例6: setFontColorPer
void Setting::setFontColorPer()
{
QFont pFont;
QColor pColor;
if(radioButtonProgFC->isChecked())
{
pFont =fontprog;
pColor =Qt::black;
}
else if(radioButtonQuranFC->isChecked())
{
pFont =fontchapter;
pColor =colorQ.currentColor();
}
else if(radioButtonTrFC->isChecked())
{
pFont =fontchapterTr;
pColor =colorTr.currentColor();
} else if(radioButtonBooksFC)
{
pFont =fontBook;
pColor =colorBook.currentColor();
}
QTextCharFormat fmt;
fmt.setForeground(pColor);
fmt.setFont(pFont);
textEditFontPerviwe->selectAll();
QTextCursor cursor = textEditFontPerviwe->textCursor();
cursor.mergeCharFormat(fmt);
textEditFontPerviwe->mergeCurrentCharFormat(fmt);
cursor.clearSelection();
textEditFontPerviwe->setTextCursor(cursor);
}
示例7: textCursor
void
SimpleRichTextEdit::setRichText(const SubtitleComposer::SString &richText)
{
setPlainText(richText.string());
QTextCursor cursor = textCursor();
cursor.setPosition(0);
int currentStyleFlags = -1;
QRgb currentStyleColor = 0;
QTextCharFormat format;
for(int position = 0, size = richText.length(); position < size; ++position) {
if(currentStyleFlags != richText.styleFlagsAt(position) || ((richText.styleFlagsAt(position) & SubtitleComposer::SString::Color) && currentStyleColor != richText.styleColorAt(position))) {
currentStyleFlags = richText.styleFlagsAt(position);
currentStyleColor = richText.styleColorAt(position);
format.setFontWeight(currentStyleFlags & SubtitleComposer::SString::Bold ? QFont::Bold : QFont::Normal);
format.setFontItalic(currentStyleFlags & SubtitleComposer::SString::Italic);
format.setFontUnderline(currentStyleFlags & SubtitleComposer::SString::Underline);
format.setFontStrikeOut(currentStyleFlags & SubtitleComposer::SString::StrikeThrough);
if((currentStyleFlags &SubtitleComposer::SString::Color) == 0)
format.setForeground(QBrush());
else
format.setForeground(QBrush(QColor(currentStyleColor)));
}
cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, 1);
cursor.mergeCharFormat(format);
cursor.setPosition(position + 1);
}
clearUndoRedoHistory();
}
示例8: stopDebugging
QString OCamlSource::stopDebugging( const QString &file, int start_char, int end_char , bool after)
{
if ( curFile != file )
loadFile( file );
QTextCharFormat unselectedFormat;
unselectedFormat.setBackground( Qt::white );
QTextCursor cur = textCursor();
cur.movePosition( QTextCursor::Start, QTextCursor::MoveAnchor );
cur.movePosition( QTextCursor::End, QTextCursor::KeepAnchor );
cur.mergeCharFormat( unselectedFormat );
cur.movePosition( QTextCursor::Start, QTextCursor::MoveAnchor );
cur.movePosition( QTextCursor::NextCharacter, QTextCursor::MoveAnchor, start_char );
setTextCursor( cur );
centerCursor();
_start_char = start_char;
_end_char = end_char;
_after = after;
timer_index = 0;
markBreakPoints(false);
markCurrentLocation();
cur.movePosition( QTextCursor::Start, QTextCursor::MoveAnchor );
cur.movePosition( QTextCursor::NextCharacter, QTextCursor::MoveAnchor, _start_char );
cur.movePosition( QTextCursor::NextCharacter, QTextCursor::KeepAnchor, _end_char - _start_char );
QString text = cur.selectedText();
return text;
}
示例9: mergeFormatOnWordOrSelection
void DocumentHandler::mergeFormatOnWordOrSelection(const QTextCharFormat &format)
{
QTextCursor cursor = textCursor();
if (!cursor.hasSelection())
cursor.select(QTextCursor::WordUnderCursor);
cursor.mergeCharFormat(format);
}
示例10: mergeFormatOnWordOrSelection
void XYZTextEditor::mergeFormatOnWordOrSelection(const QTextCharFormat &format) {
QTextCursor cursor = m_ui->textEdit->textCursor();
if (!cursor.hasSelection())
cursor.select(QTextCursor::WordUnderCursor);
cursor.mergeCharFormat(format);
m_ui->textEdit->mergeCurrentCharFormat(format);
}
示例11: mergeFormatOnWordOrSelection
void MailEditorMainWindow::mergeFormatOnWordOrSelection(const QTextCharFormat &format)
{
QTextCursor cursor = ui->messageEdit->textCursor();
if(cursor.hasSelection() == false)
cursor.select(QTextCursor::WordUnderCursor);
cursor.mergeCharFormat(format);
ui->messageEdit->mergeCurrentCharFormat(format);
}
示例12: setTextCursorFont
void FormattedTextWidget::setTextCursorFont( const QFont &font )
{
QTextCursor cursor = d->m_description->textCursor();
QTextCharFormat format;
format.setFontFamily( font.family() );
cursor.mergeCharFormat( format );
d->m_description->setTextCursor( cursor );
}
示例13: setTextCursorUnderlined
void FormattedTextWidget::setTextCursorUnderlined( bool underlined )
{
QTextCursor cursor = d->m_description->textCursor();
QTextCharFormat format;
format.setFontUnderline( underlined );
cursor.mergeCharFormat( format );
d->m_description->setTextCursor( cursor );
}
示例14: setTextCursorItalic
void FormattedTextWidget::setTextCursorItalic( bool italic )
{
QTextCursor cursor = d->m_description->textCursor();
QTextCharFormat format;
format.setFontItalic( italic );
cursor.mergeCharFormat( format );
d->m_description->setTextCursor( cursor );
}
示例15: setTextCursorBold
void FormattedTextWidget::setTextCursorBold( bool bold )
{
QTextCursor cursor = d->m_description->textCursor();
QTextCharFormat format;
format.setFontWeight( bold ? QFont::Bold : QFont::Normal );
cursor.mergeCharFormat( format );
d->m_description->setTextCursor( cursor );
}