qlabel centering



  • 1 Answer(s)

    The qlabel centering:

    The text in a QLabel by call the  QLabel::setAlignment  . The Layout  will be automatic resized the widget  in the Layout Management

    #include <QApplication>
    #include <QHBoxLayout>
    #include <QLabel>
    #include <QWidget>
     
    int main(int argc, char* argv[]) {
        QApplication app(argc, argv);
     
        QLabel* label=new QLabel("Hello World!");
        label->setAlignment(Qt::AlignCenter);
     
        QWidget* widget=new QWidget;
     
        // create horizontal layout
        QHBoxLayout* layout=new QHBoxLayout;
        // and add label to it
        layout->addWidget(label);
        // set layout to widget
        widget->setLayout(layout);
     
        widget->show();
     
        return app.exec();
    }
    
    Answered on January 11, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.