Center the Text of QTextEdit horizontally and vertically
问题 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", m_ui->centralWidget); m_myTextEdit->setGeometry(5, 50, 400, 250); m_myTextEdit->setReadOnly(true); m_myTextEdit->setAlignment(Qt::AlignCenter); Is there a opportunity to set it centered with a StyleSheet? 回答1: If you only need one line, you can use a QLineEdit instead: QLineEdit* lineEdit = new QLineEdit("centered text"); lineEdit->setAlignment(Qt: