MCPcopy Create free account
hub / github.com/Kitware/ParaView / getFirstVisibleBlockId

Function getFirstVisibleBlockId

Qt/Python/pqPythonUtils.h:22–47  ·  view source on GitHub ↗

* @brief Returns the id of the first visible block inside a QTextEdit * @details Taken from * Stackoverflow */

Source from the content-addressed store, hash-verified

20 * href="https://stackoverflow.com/questions/2443358/how-to-add-lines-numbers-to-qtextedit/24596246#24596246">Stackoverflow</a>
21 */
22inline std::int32_t getFirstVisibleBlockId(const QTextEdit& text)
23{
24 QTextCursor curs = QTextCursor(text.document());
25 curs.movePosition(QTextCursor::Start);
26 for (std::int32_t i = 0; i < text.document()->blockCount(); ++i)
27 {
28 QTextBlock block = curs.block();
29
30 QRect r1 = text.viewport()->geometry();
31 QRect r2 = text.document()
32 ->documentLayout()
33 ->blockBoundingRect(block)
34 .translated(text.viewport()->geometry().x(),
35 text.viewport()->geometry().y() - (text.verticalScrollBar()->sliderPosition()))
36 .toRect();
37
38 if (r1.contains(r2, true))
39 {
40 return i;
41 }
42
43 curs.movePosition(QTextCursor::NextBlock);
44 }
45
46 return 0;
47};
48
49inline QString stripFilename(const QString& filepath)
50{

Callers 1

paintEventMethod · 0.85

Calls 1

containsMethod · 0.45

Tested by

no test coverage detected