本文整理汇总了C++中QTextFrameFormat::setPadding方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextFrameFormat::setPadding方法的具体用法?C++ QTextFrameFormat::setPadding怎么用?C++ QTextFrameFormat::setPadding使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextFrameFormat
的用法示例。
在下文中一共展示了QTextFrameFormat::setPadding方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QwtRichTextDocument
QwtRichTextDocument( const QString &text, int flags, const QFont &font )
{
setUndoRedoEnabled( false );
setDefaultFont( font );
setHtml( text );
// make sure we have a document layout
( void )documentLayout();
QTextOption option = defaultTextOption();
if ( flags & Qt::TextWordWrap )
option.setWrapMode( QTextOption::WordWrap );
else
option.setWrapMode( QTextOption::NoWrap );
option.setAlignment( ( Qt::Alignment ) flags );
setDefaultTextOption( option );
QTextFrame *root = rootFrame();
QTextFrameFormat fm = root->frameFormat();
fm.setBorder( 0 );
fm.setMargin( 0 );
fm.setPadding( 0 );
fm.setBottomMargin( 0 );
fm.setLeftMargin( 0 );
root->setFrameFormat( fm );
adjustSize();
}
示例2: appendMessageToCurrentSession
/*! Append a new message to the current session and scroll to the end of the message protocol and
returns true if the action was successful. The \a messageColor defines the color of the message
box and should be provided as a full-color (no dimming required) color, as it is automatically
adjusted for the border and background.
*/
bool QwcPrivateMessager::appendMessageToCurrentSession(QTextDocument *document, const QString message, const QColor messageColor)
{
if (!document) { return false; }
QTextCursor cursor = document->rootFrame()->lastCursorPosition();
cursor.movePosition(QTextCursor::StartOfBlock);
QTextFrameFormat frameFormat;
frameFormat.setPadding(4);
frameFormat.setBackground(messageColor.lighter(190));
frameFormat.setMargin(0);
frameFormat.setBorder(2);
frameFormat.setBorderBrush(messageColor.lighter(150));
frameFormat.setBorderStyle(QTextFrameFormat::BorderStyle_Outset);
// Title
QTextCharFormat backupCharFormat = cursor.charFormat();
QTextCharFormat newCharFormat;
newCharFormat.setFontPointSize(9);
QTextBlockFormat headerFormat;
headerFormat.setAlignment(Qt::AlignHCenter);
cursor.insertBlock(headerFormat);
cursor.setCharFormat(newCharFormat);
cursor.insertText(QDateTime::currentDateTime().toString());
QTextFrame *frame = cursor.insertFrame(frameFormat);
cursor.setCharFormat(backupCharFormat);
frame->firstCursorPosition().insertText(message);
return true;
}
示例3: edit
text_writer( docEdit& e ) : edit( e ) {
QTextCursor cursor = edit.textCursor();
cursor.movePosition( QTextCursor::Start );
mainFrame = cursor.currentFrame();
plainFormat = cursor.charFormat();
plainFormat.setFontPointSize( 10 );
paragraphFormat = plainFormat;
paragraphFormat.setFontPointSize( 12 );
headingFormat = plainFormat;
headingFormat.setFontWeight( QFont::Bold );
headingFormat.setFontPointSize( 16 );
empasisFormat = plainFormat;
empasisFormat.setFontItalic( true );
tagFormat = plainFormat;
tagFormat.setForeground( QColor( "#990000" ) );
tagFormat.setFontUnderline( true );
underlineFormat = plainFormat;
underlineFormat.setFontUnderline( true );
frameFormat.setBorderStyle( QTextFrameFormat::BorderStyle_Inset );
frameFormat.setBorder( 1 );
frameFormat.setMargin( 10 );
frameFormat.setPadding( 4 );
}
示例4: QMainWindow
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
// 获取文档对象
QTextDocument *document = ui->textEdit->document();
// 获取根框架
QTextFrame *rootFrame = document->rootFrame();
// 创建框架格式
QTextFrameFormat format;
// 边界颜色
format.setBorderBrush(Qt::red);
// 边界宽度
format.setBorder(3);
// 框架使用格式
rootFrame->setFrameFormat(format);
QTextFrameFormat frameFormat;
// 设置背景颜色
frameFormat.setBackground(Qt::lightGray);
// 设置边距
frameFormat.setMargin(10);
// 设置填衬
frameFormat.setPadding(5);
frameFormat.setBorder(2);
frameFormat.setBorderStyle(QTextFrameFormat::BorderStyle_Dotted); //设置边框样式
// 获取光标
QTextCursor cursor = ui->textEdit->textCursor();
// 在光标处插入框架
cursor.insertFrame(frameFormat);
//以下是5.2.2节内容
QAction *action_textFrame = new QAction(tr("框架"),this);
connect(action_textFrame,SIGNAL(triggered()),this,SLOT(showTextFrame()));
// 在工具栏添加动作
ui->mainToolBar->addAction(action_textFrame);
QAction *action_textBlock = new QAction(tr("文本块"),this);
connect(action_textBlock,SIGNAL(triggered()),this,SLOT(showTextBlock()));
ui->mainToolBar->addAction(action_textBlock);
QAction *action_font = new QAction(tr("字体"),this);
// 设置动作可以被选中
action_font->setCheckable(true);
connect(action_font,SIGNAL(toggled(bool)),this,SLOT(setTextFont(bool)));
ui->mainToolBar->addAction(action_font);
}
示例5: contentsBuilder
void KDReports::Frame::build( ReportBuilder& builder ) const
{
// prepare the frame
QTextFrameFormat format;
if ( d->m_width ) {
if ( d->m_widthUnit == Millimeters ) {
format.setWidth( QTextLength( QTextLength::FixedLength, mmToPixels( d->m_width ) ) );
} else {
format.setWidth( QTextLength( QTextLength::PercentageLength, d->m_width ) );
}
}
if ( d->m_height ) {
if ( d->m_heightUnit == Millimeters ) {
format.setHeight( QTextLength( QTextLength::FixedLength, mmToPixels( d->m_height ) ) );
} else {
format.setHeight( QTextLength( QTextLength::PercentageLength, d->m_height ) );
}
}
format.setPadding( mmToPixels( padding() ) );
format.setBorder( d->m_border );
// TODO borderBrush like in AbstractTableElement
format.setPosition( QTextFrameFormat::InFlow );
QTextCursor& textDocCursor = builder.cursor();
QTextFrame *frame = textDocCursor.insertFrame(format);
QTextCursor contentsCursor = frame->firstCursorPosition();
ReportBuilder contentsBuilder( builder.currentDocumentData(),
contentsCursor, builder.report() );
contentsBuilder.copyStateFrom( builder );
foreach( const KDReports::ElementData& ed, d->m_elements )
{
switch ( ed.m_type ) {
case KDReports::ElementData::Inline:
contentsBuilder.addInlineElement( *ed.m_element );
break;
case KDReports::ElementData::Block:
contentsBuilder.addBlockElement( *ed.m_element, ed.m_align );
break;
case KDReports::ElementData::Variable:
contentsBuilder.addVariable( ed.m_variableType );
break;
}
}
textDocCursor.movePosition( QTextCursor::End );
}
示例6: HandlePrint
/* form qtexdocument to this margin an papersize */
void M_PageSize::HandlePrint( QTextDocument *doc )
{
const qreal RightMargin = P_margin.y();
const qreal LeftMargin = P_margin.height();
const qreal LargeDoc = G_regt.width() - RightMargin - LeftMargin;
doc->setPageSize ( G_regt.size() );
QTextFrame *Tframe = doc->rootFrame();
QTextFrameFormat Ftf = Tframe->frameFormat();
Ftf.setLeftMargin(P_margin.height());
Ftf.setBottomMargin(P_margin.width());
Ftf.setTopMargin(P_margin.x());
Ftf.setBackground(QBrush(Qt::transparent));
Ftf.setRightMargin(P_margin.y());
Ftf.setPadding ( 0);
Tframe->setFrameFormat(Ftf);
doc->setPageSize ( G_regt.size() );
}
示例7: newLetter
//! [2]
void MainWindow::newLetter()
{
textEdit->clear();
QTextCursor cursor(textEdit->textCursor());
cursor.movePosition(QTextCursor::Start);
QTextFrame *topFrame = cursor.currentFrame();
QTextFrameFormat topFrameFormat = topFrame->frameFormat();
topFrameFormat.setPadding(16);
topFrame->setFrameFormat(topFrameFormat);
QTextCharFormat textFormat;
QTextCharFormat boldFormat;
boldFormat.setFontWeight(QFont::Bold);
QTextCharFormat italicFormat;
italicFormat.setFontItalic(true);
QTextTableFormat tableFormat;
tableFormat.setBorder(1);
tableFormat.setCellPadding(16);
tableFormat.setAlignment(Qt::AlignRight);
cursor.insertTable(1, 1, tableFormat);
cursor.insertText("The Firm", boldFormat);
cursor.insertBlock();
cursor.insertText("321 City Street", textFormat);
cursor.insertBlock();
cursor.insertText("Industry Park");
cursor.insertBlock();
cursor.insertText("Some Country");
cursor.setPosition(topFrame->lastPosition());
cursor.insertText(QDate::currentDate().toString("d MMMM yyyy"), textFormat);
cursor.insertBlock();
cursor.insertBlock();
cursor.insertText("Dear ", textFormat);
cursor.insertText("NAME", italicFormat);
cursor.insertText(",", textFormat);
for (int i = 0; i < 3; ++i)
cursor.insertBlock();
cursor.insertText(tr("Yours sincerely,"), textFormat);
for (int i = 0; i < 3; ++i)
cursor.insertBlock();
cursor.insertText("The Boss", textFormat);
cursor.insertBlock();
cursor.insertText("ADDRESS", italicFormat);
}
示例8: newLetter
void MainWindow::newLetter(){
chatbox->clear();
QTextCursor cursor(chatbox->textCursor());
cursor.movePosition(QTextCursor::Start);
QTextFrame *topFrame = cursor.currentFrame();
QTextFrameFormat topFrameFormat = topFrame->frameFormat();
topFrameFormat.setPadding(16);
topFrame->setFrameFormat(topFrameFormat);
QTextCharFormat textFormat;
QTextCharFormat boldFormat;
boldFormat.setFontWeight(QFont::Bold);
QTextCharFormat italicFormat;
italicFormat.setFontItalic(true);
/*QTextTableFormat tableFormat;
tableFormat.setBorder(1);
tableFormat.setCellPadding(16);
tableFormat.setAlignment(Qt::AlignRight);
cursor.insertTable(1, 1, tableFormat);
cursor.insertText("The Firm", boldFormat);
cursor.insertBlock();
cursor.insertText("321 City Street", textFormat);
cursor.insertBlock();
cursor.insertText("Industry Park");
cursor.insertBlock();
cursor.insertText("Some Country"); */
cursor.setPosition(topFrame->lastPosition());
cursor.insertText("Railguy: ", boldFormat);
cursor.insertText("lol nub", textFormat);
cursor.insertBlock();
cursor.insertText("Chaos: ", boldFormat);
cursor.insertText("nou", textFormat);
cursor.insertBlock();
QFont font = chattitle->font();
font.setBold(true);
chattitle->setFont(font);
chattitle->setText("#General");
}
示例9: execute
/*!
* \class TextCursorChangePadding
* \author Anders Fernström
* \date 2005-11-03
* \date 2005-11-07 (update)
*
* \brief Command for changing padding
*
* 2005-11-07 AF, implemented the function
*/
void TextCursorChangePadding::execute()
{
QTextEdit *editor = document()->getCursor()->currentCell()->textEdit();
if( editor )
{
QTextFrameFormat format = editor->document()->rootFrame()->frameFormat();
format.setPadding( padding_ );
editor->document()->rootFrame()->setFrameFormat( format );
// create a rule for the padding
QString ruleValue;
ruleValue.setNum( padding_ );
Rule *rule = new Rule( "OMNotebook_Padding", ruleValue );
document()->getCursor()->currentCell()->addRule( rule );
// update the cells style
document()->getCursor()->currentCell()->style()->textFrameFormat()->setPadding( padding_ );
}
}
示例10: cursor
MainWindow::MainWindow()
{
QMenu *fileMenu = new QMenu(tr("&File"));
QAction *saveAction = fileMenu->addAction(tr("&Save..."));
saveAction->setShortcut(tr("Ctrl+S"));
QAction *quitAction = fileMenu->addAction(tr("E&xit"));
quitAction->setShortcut(tr("Ctrl+Q"));
menuBar()->addMenu(fileMenu);
editor = new QTextEdit();
QTextCursor cursor(editor->textCursor());
cursor.movePosition(QTextCursor::Start);
QTextFrame *mainFrame = cursor.currentFrame();
QTextCharFormat plainCharFormat;
QTextCharFormat boldCharFormat;
boldCharFormat.setFontWeight(QFont::Bold);
/* main frame
//! [0]
QTextFrame *mainFrame = cursor.currentFrame();
cursor.insertText(...);
//! [0]
*/
cursor.insertText("Text documents are represented by the "
"QTextDocument class, rather than by QString objects. "
"Each QTextDocument object contains information about "
"the document's internal representation, its structure, "
"and keeps track of modifications to provide undo/redo "
"facilities. This approach allows features such as the "
"layout management to be delegated to specialized "
"classes, but also provides a focus for the framework.",
plainCharFormat);
//! [1]
QTextFrameFormat frameFormat;
frameFormat.setMargin(32);
frameFormat.setPadding(8);
frameFormat.setBorder(4);
//! [1]
cursor.insertFrame(frameFormat);
/* insert frame
//! [2]
cursor.insertFrame(frameFormat);
cursor.insertText(...);
//! [2]
*/
cursor.insertText("Documents are either converted from external sources "
"or created from scratch using Qt. The creation process "
"can done by an editor widget, such as QTextEdit, or by "
"explicit calls to the Scribe API.", boldCharFormat);
cursor = mainFrame->lastCursorPosition();
/* last cursor
//! [3]
cursor = mainFrame->lastCursorPosition();
cursor.insertText(...);
//! [3]
*/
cursor.insertText("There are two complementary ways to visualize the "
"contents of a document: as a linear buffer that is "
"used by editors to modify the contents, and as an "
"object hierarchy containing structural information "
"that is useful to layout engines. In the hierarchical "
"model, the objects generally correspond to visual "
"elements such as frames, tables, and lists. At a lower "
"level, these elements describe properties such as the "
"style of text used and its alignment. The linear "
"representation of the document is used for editing and "
"manipulation of the document's contents.",
plainCharFormat);
connect(saveAction, SIGNAL(triggered()), this, SLOT(saveFile()));
connect(quitAction, SIGNAL(triggered()), this, SLOT(close()));
setCentralWidget(editor);
setWindowTitle(tr("Text Document Frames"));
}
示例11: createPages
void KWQTableView::createPages(QPrinter *printer, QTextDocument *textDoc, bool sendToPrinter)
{
printer->setFullPage(true);
int myDpi = printer->logicalDpiY();
if (Prefs::printStyle() == Prefs::EnumPrintStyle::Flashcard) {
printer->setOrientation(QPrinter::Landscape);
int cardWidth = qRound(5 * qreal(myDpi));
int cardHeight = qRound(3 * qreal(myDpi));
QTextTable *table = textDoc->rootFrame()->lastCursorPosition().insertTable(model()->rowCount(), 2);
QTextTableFormat tableFormat = table->format();
tableFormat.setHeaderRowCount(0);
tableFormat.setBorderStyle(QTextFrameFormat::BorderStyle_None);
tableFormat.setCellSpacing(0);
tableFormat.setCellPadding(0);
QVector<QTextLength> constraints;
constraints.append(QTextLength(QTextLength::FixedLength, cardWidth));
constraints.append(QTextLength(QTextLength::FixedLength, cardWidth));
tableFormat.setColumnWidthConstraints(constraints);
table->setFormat(tableFormat);
QTextBlockFormat headerFormat;
headerFormat.setAlignment(Qt::AlignLeft);
QTextCharFormat headerCharFormat;
headerCharFormat.setFont(QFontDatabase::systemFont(QFontDatabase::GeneralFont));
QTextBlockFormat cellFormat;
cellFormat.setAlignment(Qt::AlignCenter);
QTextCharFormat cellCharFormat;
cellCharFormat.setFont(Prefs::editorFont());
QTextFrameFormat cardFormat;
cardFormat.setBorder(1);
cardFormat.setBorderStyle(QTextFrameFormat::BorderStyle_Solid);
cardFormat.setBorderBrush(QBrush(Qt::black));
cardFormat.setWidth(QTextLength(QTextLength::FixedLength, cardWidth));
cardFormat.setHeight(QTextLength(QTextLength::FixedLength, cardHeight));
cardFormat.setPadding(qRound(0.25 * myDpi));
QTextFrameFormat lineFormat;
lineFormat.setBorder(1);
lineFormat.setBorderStyle(QTextFrameFormat::BorderStyle_Solid);
lineFormat.setBorderBrush(QBrush(Qt::black));
lineFormat.setWidth(QTextLength(QTextLength::FixedLength, qRound(4.5 * myDpi)));
lineFormat.setHeight(1.1); //1 is drawn as a box whereas this is drawn as a line. Strange...
lineFormat.setPadding(0);
QTextFrame *card;
for (int i = 0; i < model()->rowCount(); i++) {
for (int j = 0; j < model()->columnCount(); j++) {
cardFormat.setPosition(QTextFrameFormat::FloatLeft);
card = table->cellAt(i, j).firstCursorPosition().insertFrame(cardFormat);
card->lastCursorPosition().insertText(model()->headerData(j, Qt::Horizontal, Qt::DisplayRole).toString(), headerCharFormat);
card->lastCursorPosition().insertFrame(lineFormat);
card->lastCursorPosition().insertBlock();
card->lastCursorPosition().insertBlock();
card->lastCursorPosition().insertBlock(cellFormat, cellCharFormat);
card->lastCursorPosition().insertText(model()->data(model()->index(i, j)).toString(), cellCharFormat);
}
}
}
else
{
textDoc->rootFrame()->lastCursorPosition().insertText(QStringLiteral("kwordquiz %1").arg(KWQ_VERSION));
if (Prefs::printStyle() == Prefs::EnumPrintStyle::Exam)
textDoc->rootFrame()->lastCursorPosition().insertText(' ' + i18n("Name:_____________________________ Date:__________"));
QTextTable* table;
if (Prefs::printStyle() == Prefs::EnumPrintStyle::Exam)
table = textDoc->rootFrame()->lastCursorPosition().insertTable(model()->rowCount() + 1, model()->columnCount() + 2);
else
table = textDoc->rootFrame()->lastCursorPosition().insertTable(model()->rowCount() + 1, model()->columnCount() + 1);
QTextTableFormat tableFormat = table->format();
tableFormat.setHeaderRowCount(1);
tableFormat.setBorder(1);
tableFormat.setBorderStyle(QTextFrameFormat::BorderStyle_Solid);
tableFormat.setCellSpacing(0);
tableFormat.setBorderBrush(QBrush(Qt::black));
tableFormat.setCellPadding(2);
QVector<QTextLength> constraints;
constraints.append(QTextLength(QTextLength::FixedLength, verticalHeader()->width()));
constraints.append(QTextLength(QTextLength::FixedLength, columnWidth(0)));
constraints.append(QTextLength(QTextLength::FixedLength, columnWidth(1)));
if (Prefs::printStyle() == Prefs::EnumPrintStyle::Exam)
constraints.append(QTextLength(QTextLength::FixedLength, 50));
tableFormat.setColumnWidthConstraints(constraints);
table->setFormat(tableFormat);
QTextBlockFormat headerFormat;
//.........这里部分代码省略.........
示例12: printCalc
//.........这里部分代码省略.........
textFormat.setForeground(QBrush(printSettings.tableHeaderColor));
}
print.setHeaders(columns);
CalculatedItem::Data allResult;
for (const auto &deliverer: deliverers)
{
row++;
const CalculatedItem::Data calcItem = deliverer->getCalculations();
print.addRow(itemToPrintRow(deliverer->name(), calcItem, row));
allResult += calcItem;
}
int mergeCount = 0;
auto itemRow = itemToPrintRow("Итого", allResult, row);
for (int i = 0; i < Constants::PrintColumns::Liters; i++) {
const auto &col = printColumns[i];
if (col.isShow)
mergeCount++;
}
QTextCharFormat resultFormat;
resultFormat.setFont(printSettings.tableResultFont);
resultFormat.setForeground(QBrush(printSettings.tableResultColor));
print.addRow(itemRow, resultFormat, mergeCount);
auto &cursor = print.cursor();
cursor.setPosition(0);
QTextFrameFormat topFrameFormat;
topFrameFormat.setPadding(4);
cursor.insertFrame(topFrameFormat);
QTextBlockFormat textBlockFormat;
textBlockFormat.setBottomMargin(4);
textBlockFormat.setAlignment(Qt::AlignLeft);
QTextBlockFormat captionBlockFormat;
captionBlockFormat.setAlignment(Qt::AlignCenter);
cursor.setBlockFormat(textBlockFormat);
QTextCharFormat textCharFormat;
textCharFormat.setFont(printSettings.textFont);
QTextCharFormat captionCharFormat;
captionCharFormat.setFont(printSettings.captionTextFont);
captionCharFormat.setForeground(QBrush(printSettings.captionColor));
cursor.insertText(settings->getFirmName(), textCharFormat);
cursor.insertBlock();
cursor.setBlockFormat(captionBlockFormat);
auto dateMin = QDate(), dateMax = QDate();
if (isCalcByDate()) {
dateMin = ui->dateEditFilterStart->date();
dateMax = ui->dateEditFilterEnd->date();
} else {
dateMin = milkReception->getMinDeliveryDate();
dateMax = milkReception->getMaxDeliveryDate();
}
const auto s = dateMax == dateMin ? tr("%1 число").arg(dateMin.toString(Constants::defaultDateFormat())) :