Reputation: 189
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
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