Currently, I am adding text data into qtextbrowser. In this data, there is a hyperlink(that I am capturing using qregex) and a filepath(for one of my directories). Now, on click of the hyperlink, I want to open the link in one of the browsers of linux. Here I am able to open the hyperlinks in the qtextbrowser but not in the external tools. And on click of filepath, I have to open a terminal at that location.I couldn't how to add actions to the text in the qt.
I couldn't find any appropriate solution.
The code for appending hyperlink: and dirPath
.hpp file
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow: public QMainWindow{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
.cpp file
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QString hyperLink = QString::fromStdString("https://www.google.co.in/");
hyperLink = QString::fromStdString("<a href = \"") + hyperLink +
QString::fromStdString("\" >") + hyperLink + QString::fromStdString("</a>");
hyperLink = QString::fromStdString("HyperLink: ") + hyperLink;
ui->textBrowser->append(hyperLink);
QString dirLocation = QString::fromStdString("/home/user/dir");
dirLocation = QString::fromStdString("<a href = \"") + dirLocation +
QString::fromStdString("\" >") + dirLocation + QString::fromStdString("</a>");
dirLocation = QString::fromStdString("Working Directory: ") + dirLocation;
ui->textBrowser->append(dirLocation);
}
MainWindow::~MainWindow()
{
delete ui;
}
On the click of the hyperLink, I want to open the link in the default browser of the system.
On the click of the dirPath(that I am currently appending as hyperLink), I want to open the terminal at the dirPath.
ui->textbrowser is QWidget of QTextBrowser.
I am working in a Linux OS
Thank you for help in advance.