本文整理汇总了C++中QTextEdit::setTextFormat方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextEdit::setTextFormat方法的具体用法?C++ QTextEdit::setTextFormat怎么用?C++ QTextEdit::setTextFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextEdit
的用法示例。
在下文中一共展示了QTextEdit::setTextFormat方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: f
ShowTextDlg::ShowTextDlg(const QString &fname, bool rich, QWidget *parent, const char *name)
:QDialog(parent, name, FALSE, WDestructiveClose)
{
QString text;
QFile f(fname);
if(f.open(IO_ReadOnly)) {
QTextStream t(&f);
while(!t.eof())
text += t.readLine() + '\n';
f.close();
}
QVBoxLayout *vb1 = new QVBoxLayout(this, 8);
QTextEdit *te = new QTextEdit(this);
te->setReadOnly(TRUE);
te->setTextFormat(rich ? QTextEdit::RichText : QTextEdit::PlainText);
te->setText(text);
vb1->addWidget(te);
QHBoxLayout *hb1 = new QHBoxLayout(vb1);
hb1->addStretch(1);
QPushButton *pb = new QPushButton(tr("&OK"), this);
connect(pb, SIGNAL(clicked()), SLOT(accept()));
hb1->addWidget(pb);
hb1->addStretch(1);
resize(560, 384);
}
示例2: QLabel
RKReadLineDialog::RKReadLineDialog (QWidget *parent, const QString &caption, const QString &prompt, RCommand *command) : KDialogBase (parent, 0, true, caption, KDialogBase::Ok | KDialogBase::Cancel) {
RK_TRACE (DIALOGS);
RK_ASSERT (command);
QVBox *page = makeVBoxMainWidget ();
new QLabel (caption, page);
int screen_width = qApp->desktop ()->width () - 2*marginHint() - 2*spacingHint (); // TODO is this correct on xinerama?
QString context = command->fullOutput ();
if (!context.isEmpty ()) {
new QLabel (i18n ("Context:"), page);
QTextEdit *output = new QTextEdit (page);
output->setUndoRedoEnabled (false);
output->setTextFormat (QTextEdit::PlainText);
output->setCurrentFont (QFont ("Courier"));
output->setWordWrap (QTextEdit::NoWrap);
output->setText (context);
output->setReadOnly (true);
int cwidth = output->contentsWidth ();
output->setMinimumWidth (screen_width < cwidth ? screen_width : cwidth);
output->scrollToBottom ();
output->setFocusPolicy (QWidget::NoFocus);
}
QLabel *promptl = new QLabel (prompt, page);
promptl->setAlignment (Qt::WordBreak | promptl->alignment ());
input = new QLineEdit (QString (), page);
input->setMinimumWidth (fontMetrics ().maxWidth ()*20);
input->setFocus ();
}
示例3: fileNew
void TextEdit::fileNew()
{
QTextEdit *edit = new QTextEdit( tabWidget );
edit->setTextFormat( RichText );
doConnections( edit );
tabWidget->addTab( edit, tr( "noname" ) );
tabWidget->showPage( edit );
edit->viewport()->setFocus();
}
示例4: load
void TextEdit::load( const QString &f )
{
if ( !QFile::exists( f ) )
return;
QTextEdit *edit = new QTextEdit( tabWidget );
doConnections( edit );
tabWidget->addTab( edit, QFileInfo( f ).fileName() );
QFile fl( f );
fl.open( IO_ReadOnly );
QByteArray array = fl.readAll();
array.resize( array.size() +1 );
array[ (int)array.size() - 1 ] = '\0';
QString text = ( f.find( "bidi.txt" ) != -1 ? QString::fromUtf8( array.data() ) : QString::fromLatin1( array.data() ) );
edit->setText( text );
edit->viewport()->setFocus();
edit->setTextFormat( Qt::RichText );
}
示例5: load
void TextEdit::load( const QString &f )
{
if ( !QFile::exists( f ) )
return;
QTextEdit *edit = new QTextEdit( tabWidget );
edit->setTextFormat( RichText );
doConnections( edit );
tabWidget->addTab( edit, QFileInfo( f ).fileName() );
QFile file( f );
if ( !file.open( IO_ReadOnly ) )
return;
QTextStream ts( &file );
QString txt = ts.read();
if ( !QStyleSheet::mightBeRichText( txt ) )
txt = QStyleSheet::convertFromPlainText( txt, QStyleSheetItem::WhiteSpacePre );
edit->setText( txt );
tabWidget->showPage( edit );
edit->viewport()->setFocus();
filenames.replace( edit, f );
}
示例6: if
int
QUimTextUtil::acquireSelectionTextInQTextEdit( enum UTextOrigin origin,
int former_req_len,
int latter_req_len,
char **former, char **latter )
{
QTextEdit *edit = (QTextEdit *)mWidget;
QString text;
int len, offset, newline;
int start_para, start_index, end_para, end_index;
int para, index;
bool cursor_at_beginning = false;
TextFormat format;
if ( ! edit->hasSelectedText() )
return -1;
format = edit->textFormat();
edit->setTextFormat( Qt::PlainText );
edit->getCursorPosition( ¶, &index );
edit->getSelection(&start_para, &start_index, &end_para, &end_index, 0 );
if ( para == start_para && index == start_index )
cursor_at_beginning = true;
text = edit->selectedText();
len = text.length();
if ( origin == UTextOrigin_Beginning ||
( origin == UTextOrigin_Cursor && cursor_at_beginning ) ) {
*former = NULL;
offset = 0;
if ( latter_req_len >= 0 ) {
if ( len > latter_req_len )
offset = len - latter_req_len;
} else {
if (! ( ~latter_req_len & ( ~UTextExtent_Line | ~UTextExtent_Full ) ) ) {
edit->setTextFormat( format );
return -1;
}
if ( latter_req_len == UTextExtent_Line && ( ( newline = text.find( '\n' ) ) != -1 ) )
offset = len - newline;
}
*latter = strdup( text.left( len - offset ).utf8() );
} else if ( origin == UTextOrigin_End ||
( origin == UTextOrigin_Cursor && !cursor_at_beginning ) ) {
offset = 0;
if ( former_req_len >= 0 ) {
if ( len > former_req_len )
offset = len - former_req_len;
} else {
if (! ( ~former_req_len & ( ~UTextExtent_Line | ~UTextExtent_Full ) ) ) {
edit->setTextFormat( format );
return -1;
}
if ( former_req_len == UTextExtent_Line && ( ( newline = text.findRev( '\n' ) ) != -1 ) )
offset = newline + 1;
}
*former = strdup( text.mid( offset, len - offset ).utf8() );
*latter = NULL;
} else {
edit->setTextFormat( format );
return -1;
}
edit->setTextFormat( format );
return 0;
}