문제

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.

도움이 되었습니까?

해결책

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!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top