Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QLabel in the center of a QWidget
Forum Updated to NodeBB v4.3 + New Features

QLabel in the center of a QWidget

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 9.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    beowulf
    wrote on last edited by
    #1

    @
    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.

    -- 0x00

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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 redundant

      QVBoxLayout* layout = new QVBoxLayout();
      layout->addWidget(MyLogoLabel);
      setLayout(layout);
      

      }
      @

      Btw. identifier names starting with capital letter are usually used for class names not variables.

      1 Reply Last reply
      0
      • B Offline
        B Offline
        beowulf
        wrote on last edited by
        #3

        [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 redundant

        QVBoxLayout* 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.

        -- 0x00

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved