user1304228
user1304228

Reputation: 189

Qt designer adding a link to a QPushButton

I have a QPushButton in QT that I need to have redirect to a website, currently the button does not go anywhere when I inherited it. I have never worked with QT before so am looking for what would need to be done to make this button redirect to a URL when hit.

Right now the properties for it have

QObject QWidget QAbstractButton QPushButton

Please help :)

Upvotes: 1

Views: 2753

Answers (1)

aMaia
aMaia

Reputation: 99

You can extend QPushButon:

#include <QDesktopServices>
#include <QUrl>
#include "LinkButton.h"

LinkButton::LinkButton(QWidget *parent) : QPushButton(parent) {
    this->setFlat(true);
    connect(this, SIGNAL(clicked()), this, SLOT(slotOpenUrl()));
}

void LinkButton::setUrl(QString url) {
    this->url = url;
}

void LinkButton::slotOpenUrl() {
    QDesktopServices::openUrl(QUrl(this->url));
}

Upvotes: 1

Related Questions