Qlabel hyperlink not working
-
I want to create a link to open another page, I tried this from the documentation i saw online but its not working. Any help.
self.ui.label_5.linkActivated.connect(self.linkClicked) def linkClicked(self): self.ui.stackedWidget.setCurrentWidget(self.ui.page)
-
@LT-K101
Put aprint()
insidelinkClicked()
. If it does not hit it you have a signal/slot problem. If it does then it is executing thestackedWidget.setCurrentWidget()
and you need to discover what that is doing/why it does not do what you want (e.g. what is inself.ui.page
, and is that a widget which is instackedWidget
?). -
@JonB Thanks for your reply, I have
print()
inside thelinkClicked()
and also setself.label_5.setOpenExternalLinks(True)
but nothing happens. Theself.ui.page
is a widget in the stackedwidget, which i want the Qlabel to point to when i click on the label. It's kind of strange or is there another Qlabel signal/slot that can achieve this task? -
@LT-K101
Put in aprint()
to make 100% sure thelinkActivated.connect(self.linkClicked)
statement is actually executed. Make sure you are clickinglabel_5
. You could try thelinkHovered
signal to see if you get that (note that per a bug report this is only emitted a single time for any given link, but that should be enough to verify).Ah, stop! The Qt docs don't make this clear at all, but it looks like whether it is emitted or not depends on what you put in the
QLabel
. You have to make it be an HTML link. See e.g. https://www.qtcentre.org/threads/20568-linkActivated-signal-in-QLabellinkActivated is emitted if you click a HTML link (a). And since you set the text 'label' the signal newer will get emitted.