如何设置QTextEdit的行数? [英] How to set number of lines for an QTextEdit?

查看:113
本文介绍了如何设置QTextEdit的行数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将QTextEdit用于某些输入.但是我想调整盒子的高度.我可以根据一次要显示的行数来设置高度吗?

I use a QTextEdit for some inputs. But I want to adjust the height of the box. Can I set the height based on the number of lines I want to have visible at a time?

推荐答案

如果您使用 QPlainTextEdit ,则应使用以下方法:

If you use QPlainTextEdit, something like this should do the trick:

void SetHeight (QPlainTextEdit* edit, int nRows)
  {
  QFontMetrics m (edit -> font()) ;
  int RowHeight = m.lineSpacing() ;
  edit -> setFixedHeight  (nRows * RowHeight) ;
  }

您可能需要添加两个或三个像素作为边距;实验会证明一切.

You might want to add two or three pixels as margin; experiment will tell.

这篇关于如何设置QTextEdit的行数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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