Here's the full code:

mainwindow.h
Qt Code:
  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3.  
  4. #include <QMainWindow>
  5. #include <QTextBrowser>
  6. #include <QPushButton>
  7. #include <QMouseEvent>
  8. #include <QTextCursor>
  9. #include <QTextDocumentFragment>
  10.  
  11. QT_BEGIN_NAMESPACE
  12. namespace Ui { class MainWindow; }
  13. QT_END_NAMESPACE
  14.  
  15. class MainWindow : public QMainWindow
  16. {
  17. Q_OBJECT
  18.  
  19. public:
  20. explicit MainWindow(QWidget *parent = nullptr);
  21. ~MainWindow();
  22.  
  23. private slots:
  24. void handleInsert();
  25. void handleSelect();
  26. private:
  27. Ui::MainWindow *ui;
  28.  
  29. QPushButton *ButtonInsert;
  30. QTextBrowser *ListWindow;
  31. };
  32.  
  33. #endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode 

main.cpp
Qt Code:
  1. #include "mainwindow.h"
  2.  
  3. #include <QApplication>
  4.  
  5. int main(int argc, char *argv[])
  6. {
  7. QApplication a(argc, argv);
  8.  
  9. MainWindow w;
  10. w.show();
  11. return a.exec();
  12. }
To copy to clipboard, switch view to plain text mode 

mainwindow.cpp
Qt Code:
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3.  
  4. MainWindow::MainWindow(QWidget *parent)
  5. : QMainWindow(parent)
  6. , ui(new Ui::MainWindow)
  7. {
  8. ui->setupUi(this);
  9. ButtonInsert = new QPushButton("Insert", this);
  10. ButtonInsert -> setGeometry(QRect(QPoint(440,90), QSize(100,30)));
  11.  
  12. ListWindow = new QTextBrowser(this);
  13. ListWindow -> setGeometry(QRect(QPoint(50,50), QSize(300,500)));
  14. ListWindow -> setText("This is a test");
  15.  
  16. connect(ListWindow, &QTextBrowser::cursorPositionChanged, this, &MainWindow::handleSelect);
  17. connect(ButtonInsert, &QPushButton::released, this, &MainWindow::handleInsert);
  18. }
  19.  
  20. MainWindow::~MainWindow()
  21. {
  22. delete ui;
  23. }
  24.  
  25. void MainWindow::handleInsert(){
  26. //test code for learning
  27. ButtonInsert->setText("Inserting...");
  28. ButtonInsert->setText("Inserted");
  29. }
  30.  
  31. void MainWindow::handleSelect(){
  32. ListWindow->moveCursor(QTextCursor::StartOfLine);
  33. ListWindow->moveCursor(QTextCursor::EndOfLine, QTextCursor::KeepAnchor);
  34. }
To copy to clipboard, switch view to plain text mode