Question

I'm trying to make a hyperlink in my application. I got two label, one of them is the hyperlink.

labelPropulsedBy = new QLabel();
    labelPropulsedBy->setText(tr("Propulsé par "));
    labelPropulsedBy->setLayout(hboxLayout);

labelWebLink = new QLabel();
    labelTripleGear->setText("<a href=\"https://www.google.ca/\">Click Here!</a>");
    labelTripleGear->setTextFormat(Qt::RichText);
    labelTripleGear->setTextInteractionFlags(Qt::TextBrowserInteraction);
    labelTripleGear->setOpenExternalLinks(true);
    labelTripleGear->setLayout(hboxLayout);

The problem is when i'm resizing my window, those two label get separated, like if there was to many spacing between them. How do you keep them together?

If there is a better way to do it please propose, i'mk trying to improve my coding habits.

Was it helpful?

Solution

Create a new horizontal spacer and add it behind the hyperlink label (or in front of the text label), this shall solve your problem. The code might looks like:

QSpacerItem *horizontalSpacer;
horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
hboxlayout->addItem(horizontalSpacer);

Also, I recommend use designer to accerlate your app design speed!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top