本文整理汇总了C++中QTextLine::rect方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextLine::rect方法的具体用法?C++ QTextLine::rect怎么用?C++ QTextLine::rect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextLine
的用法示例。
在下文中一共展示了QTextLine::rect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: paintEvent
void CodeEditor::paintEvent(QPaintEvent* event)
{
QPlainTextEdit::paintEvent(event);
QPainter painter(viewport());
painter.setPen(Qt::darkGray);
QTextBlock block = firstVisibleBlock();
QRectF rect;
do {
if (!block.isVisible())
continue;
rect = blockBoundingGeometry(block).translated(contentOffset());
QTextLine line = block.layout()->lineAt(0);
if (config->whitespaces) {
QString txt = block.text();
for (int i = 0; i < txt.length(); i++) {
// rect.x() <- учитывая горизонтальный скролинг
QPoint point(rect.x() + line.cursorToX(i), rect.y() + line.ascent());
if (txt[i] == ' ')
painter.drawText(point, QChar(0x00b7));
else if (txt[i] == '\t')
painter.drawText(point, QChar(0x21b9));
}
}
int state = block.userState();
if (!(state & Error) && state & Folded) {
QRect collapseRect(rect.x() + line.rect().x() + line.naturalTextWidth() + FONTWIDTH * 2,
rect.y() + 2, FONTWIDTH * 6, line.height() - 4);
painter.drawText(collapseRect, Qt::AlignCenter, state & Comment ? "...;" : "...)");
painter.drawRoundedRect(collapseRect, 4, 6);
}
} while ((block = block.next()).isValid() && rect.y() < viewport()->height());
}
示例2: mouseMoveEvent
void CodeEditor::mouseMoveEvent(QMouseEvent* event)
{
QTextBlock block = findBlockByY(event->pos().y());
QRect collapseRect;
if (block.isValid()) {
QRectF rect = blockBoundingGeometry(block).translated(contentOffset());
QTextLine line = block.layout()->lineAt(0);
collapseRect = QRect(rect.x() + line.rect().x() + line.naturalTextWidth() + FONTWIDTH * 2,
rect.y() + 2, FONTWIDTH * 6, line.height() - 4);
}
int state = block.userState();
if (!(state & Error) && state & Folded && collapseRect.contains(event->pos())) {
pointedBlock = block;
viewport()->setCursor(Qt::PointingHandCursor);
QString str;
while ((block = block.next()).isValid() && !block.isVisible()) {
if (str.count() > 1)
str += "\n";
if (block.blockNumber() - pointedBlock.blockNumber() > 50) {
str += "..."; // "\n...";
break;
}
str += block.text();
}
QToolTip::showText(event->globalPos(), str, this);
} else {
pointedBlock = QTextBlock();
viewport()->setCursor(Qt::IBeamCursor);
}
QPlainTextEdit::mouseMoveEvent(event);
}