Align text on center
-
How i could stop the
Loading
text from moving to the left, but still continue aligned to the center of the button?auto timer = new QTimer(); auto button = new QPushButton(this); button->setGeometry(50, 50, 200, 50); QGridLayout* layout = new QGridLayout(); button->setLayout(layout); QLabel* label = new QLabel(button); label->setStyleSheet("qproperty-alignment: AlignCenter;"); layout->addWidget(label); timer->setInterval(500); timer->start(); QObject::connect(timer, &QTimer::timeout, [=] { static int dot = 0; dot = (dot + 1) % 4; QString text = "Loading..."; text.resize(7 + dot); label->setText(text); });
-
static int dot = 0; dot = (dot + 1) % 4; QString text = QString("Loading%1").arg("",dot,'.'); text=QString("%1%2").arg(text).arg("",10-text.size(),' '); label->setText(text);
Not the best I guess ;)
anyway can't work correctly because, space and point have not the same size on not fixed font.Would be better to use a fixed left margin for the label.