Many thanks JonB.
I used the solution without layout.
Actually, before posting here, I had already tried to do it, but it wasn't working for me even though the solution wasn't very different from the code you see below that works.
Probably due to fatigue and too many attempts, my brain had started to lose its edge :D
Thanks again.
This code works:
#include <QFrame> #include <QLabel> #include "widget.h" Widget::Widget(QWidget *parent) : QWidget(parent) { QFrame *frame = new QFrame(this); frame->setStyleSheet("background-color: grey"); frame->setFixedSize(300, 200); QLabel *lbl1 = new QLabel("Label1", frame); lbl1->setStyleSheet("color: red"); QLabel *lbl2 = new QLabel("label2", frame); lbl2->setStyleSheet("color: green"); QLabel *lblCentered = new QLabel("CENTERED TEXT", frame); lblCentered->setStyleSheet("color: black"); QFont font = lbl2->font(); QFontMetrics fontMetrics(font); lbl1->move(10,180); lbl2->move(300-fontMetrics.horizontalAdvance(lbl2->text())-10,180); lblCentered->move((300-fontMetrics.horizontalAdvance(lblCentered->text()))/2, (200-fontMetrics.height())/2); }