QLabel in the center of a QWidget
-
@
void MyWidget::AnimatedLogo(QString logotype)
{QMovie *MyLogoMovie = new QMovie(logotype); MyLogoLabel = new QLabel(this); MyLogoLabel ->setMovie(MyLogoMovie); MyLogoMovie->start(); MyLogoLabel->setAlignment(Qt::AlignCenter); MyLogoLabel >show();
}
AnimatedLogo(":/mylogo.gif");
@
He is not in the center of QWidget, it always is at the top left side.
-
You need to layout the label in the parent widget:
@
void MyWidget::AnimatedLogo(QString logotype)
{
QMovie *MyLogoMovie = new QMovie(logotype);
MyLogoLabel = new QLabel();
MyLogoLabel ->setMovie(MyLogoMovie);
MyLogoMovie->start();
MyLogoLabel->setAlignment(Qt::AlignCenter);
// MyLogoLabel >show(); //this is redundantQVBoxLayout* layout = new QVBoxLayout(); layout->addWidget(MyLogoLabel); setLayout(layout);
}
@Btw. identifier names starting with capital letter are usually used for class names not variables.
-
[quote author="Krzysztof Kawa" date="1357229504"]You need to layout the label in the parent widget:
@
void MyWidget::AnimatedLogo(QString logotype)
{
QMovie *MyLogoMovie = new QMovie(logotype);
MyLogoLabel = new QLabel();
MyLogoLabel ->setMovie(MyLogoMovie);
MyLogoMovie->start();
MyLogoLabel->setAlignment(Qt::AlignCenter);
// MyLogoLabel >show(); //this is redundantQVBoxLayout* layout = new QVBoxLayout(); layout->addWidget(MyLogoLabel); setLayout(layout);
}
@Btw. identifier names starting with capital letter are usually used for class names not variables.[/quote]
THANK YOU!
bq. Btw. identifier names starting with capital letter are usually used for class names not variables.
Thanks for the tip.