[SOLVED] How can a label be linkable not to a website but to a void funtion of the program?
-
Well even if i dont assign it by UI but create it with ur code it's the same error about the emit not beeing declared..
-
In that case I don't know, it works for me, emit is the standard Qt keyword to emit a signal. Do you have the Q_OBJECT macro in the header of MyLabel as in my example?
-
There is no need to subclass QLabel.
Just set "openExternalLinks":http://qt-project.org/doc/qt-5.0/qtwidgets/qlabel.html#openExternalLinks-prop to false on connect to the "linkActivated":http://qt-project.org/doc/qt-5.0/qtwidgets/qlabel.html#linkActivated signal.
@
ui->label->setOpenExternalLinks(false);
connect(ui->label, SIGNAL(linkActivated(QString)), this, SLOT(label_clicked(QString)));void MainWindow::label_clicked(const QString &link)
{
if (link == "...") ...
}
@ -
[quote author="Lukas Geyer" date="1358770207"]There is no need to subclass QLabel.
Just set "openExternalLinks":http://qt-project.org/doc/qt-5.0/qtwidgets/qlabel.html#openExternalLinks-prop to false on connect to the "linkActivated":http://qt-project.org/doc/qt-5.0/qtwidgets/qlabel.html#linkActivated signal.
@
ui->label->setOpenExternalLinks(false);
connect(ui->label, SIGNAL(linkActivated(QString)), this, SLOT(label_clicked(QString)));void MainWindow::label_clicked(const QString &link)
{
if (link == "...") ...
}
@[/quote]and how should the text of the label be?
how will it be clickable(linkable).? -
[quote author="Leon" date="1358781102"]
and how should the text of the label be?
how will it be clickable(linkable).?[/quote]
The text SHOULD be in "Rich text" , AFAIK.
-
[quote author="Code_ReaQtor" date="1358782000"]
[quote author="Leon" date="1358781102"]and how should the text of the label be?
how will it be clickable(linkable).?[/quote]
The text SHOULD be in "Rich text" , AFAIK. [/quote]
I know that.. You click change rich text in the designer and there is a button "Insert link".
What should i put there when i want the label_clicked void to be called..?
-
Whatever you like.
@
ui->label->setText("This is text with a <a href='someLink'>link</a>.");void MainWindow::label_clicked(const QString &link)
{
if (link == "someLink") ...
}
@ -
[quote author="Lukas Geyer" date="1358782837"]Whatever you like.
@
ui->label->setText("This is text with a <a href='someLink'>link</a>.");void MainWindow::label_clicked(const QString &link)
{
if (link == "someLink") ...
}
@[/quote]Didn't know that, thanks! :)
-
[quote author="utcenter" date="1358720224"]In that case I don't know, it works for me, emit is the standard Qt keyword to emit a signal. Do you have the Q_OBJECT macro in the header of MyLabel as in my example?[/quote]
And by the way, yes i was using
#define QT_NO_KEYWORDSI just saw it...
-
You're welcome! ;-)