Center the Text of QTextEdit horizontally and vertically

前端 未结 2 508
孤城傲影
孤城傲影 2020-12-11 08:13

I want to center the text of my QTextEdit horizontally and vertically.

I tried this, but it didn\'t work.

m_myTextEdit = new QTextEdit(\"text edit\",         


        
2条回答
  •  鱼传尺愫
    2020-12-11 08:35

    If you only need one line, you can use a QLineEdit instead:

    QLineEdit* lineEdit = new QLineEdit("centered text");
    lineEdit->setAlignment(Qt::AlignCenter);
    

    If you only want to display the text, not allow the user to edit it, you can use a QLabel instead. This works with line wrapping, too:

    QLabel* label = new QLabel("centered text");
    lineEdit->setWordWrap(true);
    lineEdit->setAlignment(Qt::AlignCenter);
    

提交回复
热议问题