水平和垂直居中QTextEdit的文本 [英] Center the Text of QTextEdit horizontally and vertically

查看:10263
本文介绍了水平和垂直居中QTextEdit的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将我的QTextEdit的文本水平和垂直居中。



我试过这个,但它不工作。

  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);有没有机会使用StyleSheet设置它居中?


div class =h2_lin>解决方案

如果只需要一行,可以使用 QLineEdit

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

如果只想显示文本,不允许用户编辑它, QLabel 。这也适用于换行:

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


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?

解决方案

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);

这篇关于水平和垂直居中QTextEdit的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆