diff options
author | Friedemann Kleint <[email protected]> | 2025-01-20 13:17:34 +0100 |
---|---|---|
committer | Friedemann Kleint <[email protected]> | 2025-01-20 14:23:17 +0100 |
commit | 13dc50731724502f2f3c1fe0c8ead3081fa94c24 (patch) | |
tree | c03f1c32953205015630b0ffd0318fdebaac6318 | |
parent | 806f19d0790bbf3b5e36eceb67be1e473117fd7a (diff) |
Scriptable application: Add a status label displaying the line number
It is useful to fix errors when playing around.
Pick-to: 6.8
Change-Id: I7a656914ae30f59a5eeb1c384dc18e44389a61c5
Reviewed-by: Christian Tismer <[email protected]>
-rw-r--r-- | examples/scriptableapplication/mainwindow.cpp | 14 | ||||
-rw-r--r-- | examples/scriptableapplication/mainwindow.h | 3 |
2 files changed, 17 insertions, 0 deletions
diff --git a/examples/scriptableapplication/mainwindow.cpp b/examples/scriptableapplication/mainwindow.cpp index ece7989e7..5dc6fd7f0 100644 --- a/examples/scriptableapplication/mainwindow.cpp +++ b/examples/scriptableapplication/mainwindow.cpp @@ -5,6 +5,7 @@ #include "pythonutils.h" #include <QtWidgets/QApplication> +#include <QtWidgets/QLabel> #include <QtWidgets/QMenu> #include <QtWidgets/QMenuBar> #include <QtWidgets/QPlainTextEdit> @@ -15,6 +16,7 @@ #include <QtGui/QAction> #include <QtGui/QFontDatabase> #include <QtGui/QIcon> +#include <QtGui/QTextCursor> #include <QtCore/QDebug> #include <QtCore/QTextStream> @@ -69,6 +71,11 @@ MainWindow::MainWindow() m_scriptEdit->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont)); setCentralWidget(m_scriptEdit); + m_lineNumberLabel = new QLabel; + statusBar()->addPermanentWidget(m_lineNumberLabel, 0); + connect(m_scriptEdit, &QPlainTextEdit::cursorPositionChanged, + this, &MainWindow::slotCursorChanged); + if (!PythonUtils::bindAppObject("__main__"_L1, "mainWindow"_L1, PythonUtils::MainWindowType, this)) { statusBar()->showMessage(tr("Error loading the application module")); @@ -105,3 +112,10 @@ void MainWindow::testFunction1() qDebug().noquote() << message; statusBar()->showMessage(message); } + +void MainWindow::slotCursorChanged() +{ + auto cursor = m_scriptEdit->textCursor(); + const int line = cursor.blockNumber() + 1; + m_lineNumberLabel->setText("Line: "_L1 + QString::number(line)); +} diff --git a/examples/scriptableapplication/mainwindow.h b/examples/scriptableapplication/mainwindow.h index e72f5ca72..98af12eb5 100644 --- a/examples/scriptableapplication/mainwindow.h +++ b/examples/scriptableapplication/mainwindow.h @@ -6,6 +6,7 @@ #include <QtWidgets/QMainWindow> +QT_FORWARD_DECLARE_CLASS(QLabel) QT_FORWARD_DECLARE_CLASS(QPlainTextEdit) class MainWindow : public QMainWindow @@ -19,6 +20,7 @@ public: static constexpr auto TEST = QLatin1StringView("test"); private Q_SLOTS: + void slotCursorChanged(); void slotRunScript(); void slotPrintDiagnostics(); @@ -26,6 +28,7 @@ private: void runScript(const QString &); QPlainTextEdit *m_scriptEdit; + QLabel *m_lineNumberLabel; }; #endif // MAINWINDOW_H |