QLabel and right click
-
I have a QLabel called backgroundCalibration whose text I have set to "<a>Some text</a>"
I did:
ui->backgroundCalibration->setVisible(true); ui->backgroundCalibration->setTextInteractionFlags(Qt::LinksAccessibleByMouse); ui->backgroundCalibration->setForegroundRole(QPalette::Link); void StackingParameters::on_backgroundCalibration_linkActivated(const QString & str) { str; // // Show the popup menu // backgroundCalibrationMenu->exec(QCursor::pos()); }
When I display the Widget containing this label the text is displayed as "Some Text" and is displayed in Blue as I expected.
However when I
right-clickleft-click the text nothing happens! What crucial step did I miss?TIA
David -
I have a QLabel called backgroundCalibration whose text I have set to "<a>Some text</a>"
I did:
ui->backgroundCalibration->setVisible(true); ui->backgroundCalibration->setTextInteractionFlags(Qt::LinksAccessibleByMouse); ui->backgroundCalibration->setForegroundRole(QPalette::Link); void StackingParameters::on_backgroundCalibration_linkActivated(const QString & str) { str; // // Show the popup menu // backgroundCalibrationMenu->exec(QCursor::pos()); }
When I display the Widget containing this label the text is displayed as "Some Text" and is displayed in Blue as I expected.
However when I
right-clickleft-click the text nothing happens! What crucial step did I miss?TIA
David -
I have a QLabel called backgroundCalibration whose text I have set to "<a>Some text</a>"
I did:
ui->backgroundCalibration->setVisible(true); ui->backgroundCalibration->setTextInteractionFlags(Qt::LinksAccessibleByMouse); ui->backgroundCalibration->setForegroundRole(QPalette::Link); void StackingParameters::on_backgroundCalibration_linkActivated(const QString & str) { str; // // Show the popup menu // backgroundCalibrationMenu->exec(QCursor::pos()); }
When I display the Widget containing this label the text is displayed as "Some Text" and is displayed in Blue as I expected.
However when I
right-clickleft-click the text nothing happens! What crucial step did I miss?TIA
David@Perdrix said in QLabel and right click:
However when I right-click the text nothing happens!
What do you expect to happen?
-
Sorry I meant when I LEFT click, nothing happens
David (I'll edit the original text to correct that)
-
Yes, I'm using auto-connect and I don't get any warnings about Qt being unable to connect the signals to the slots (as I did when I originally tried to use on_backgroundCalibration_clicked() - that definitely got a complaint.
-
Yes, I'm using auto-connect and I don't get any warnings about Qt being unable to connect the signals to the slots (as I did when I originally tried to use on_backgroundCalibration_clicked() - that definitely got a complaint.
-
I added:
connect(ui->backgroundCalibration, SIGNAL(linkActivated(const Qstring &)), this, SLOT(on_backgroundCalibration_linkActivated()));
to the ctor code just after the ui->SetupUI() call.
I have a breakpoint inside the slot code at the line that is intended to raise the menu, but it is never reached.
David
-
I added:
connect(ui->backgroundCalibration, SIGNAL(linkActivated(const Qstring &)), this, SLOT(on_backgroundCalibration_linkActivated()));
to the ctor code just after the ui->SetupUI() call.
I have a breakpoint inside the slot code at the line that is intended to raise the menu, but it is never reached.
David
-
I have a QLabel called backgroundCalibration whose text I have set to "<a>Some text</a>"
I did:
ui->backgroundCalibration->setVisible(true); ui->backgroundCalibration->setTextInteractionFlags(Qt::LinksAccessibleByMouse); ui->backgroundCalibration->setForegroundRole(QPalette::Link); void StackingParameters::on_backgroundCalibration_linkActivated(const QString & str) { str; // // Show the popup menu // backgroundCalibrationMenu->exec(QCursor::pos()); }
When I display the Widget containing this label the text is displayed as "Some Text" and is displayed in Blue as I expected.
However when I
right-clickleft-click the text nothing happens! What crucial step did I miss?TIA
David -
@Perdrix
You cannot use "<a>Some text</a>" to expect a linkActivated signal.
You must set some text as the link: "<a href="any text">Some text</a>", or the text won't even look like linked. -
Yes I spotted that just after I posted and fixed it.
So the code now reads:
connect(ui->backgroundCalibration, SIGNAL(linkActivated(const QString &)), this, SLOT(on_backgroundCalibration_linkActivated(const QString &)));
and received no nastygrams about non-existent signals. Sadly the breakpoint is still not reached.
PS what's the new format for connecting the signals and slots? My book is strictly old school Qt4
David
-
Yes I spotted that just after I posted and fixed it.
So the code now reads:
connect(ui->backgroundCalibration, SIGNAL(linkActivated(const QString &)), this, SLOT(on_backgroundCalibration_linkActivated(const QString &)));
and received no nastygrams about non-existent signals. Sadly the breakpoint is still not reached.
PS what's the new format for connecting the signals and slots? My book is strictly old school Qt4
David
@Perdrix Did you read what @Bonnie wrote?
https://wiki.qt.io/New_Signal_Slot_Syntax/de -
@Perdrix
You cannot use "<a>Some text</a>" to expect a linkActivated signal.
You must set some text as the link: "<a href="any text">Some text</a>", or the text won't even look like linked. -
@Bonnie Silly question - why can't I just use <a>Text</a>? It is after all a valid minimal HTML anchor?
I shall change the code immediately to use the format you suggested.
D.