Qt - 如何在 QLineEdit 中执行上标和下标?

发布于 2024-08-25 09:51:20 字数 413 浏览 8 评论 0原文

我需要能够在 Qt 4.6 的 QLineEdit 中使用上标和下标。我知道如何在 QTextEdit 中执行上标和下标,如下所示,但我不知道如何在 QLineEdit 中执行上标和下标,因为该类不包含像 QTextEdit 那样的 mergeCurrentCharFormat() 函数。请帮忙。谢谢

void MainWindow::superscriptFormat()
{
   QTextCharFormat format;
   format.setVerticalAlignment(QTextCharFormat::AlignSuperScript);
   if(ui->txtEdit->hasFocus())
      ui->txtEdit->mergeCurrentCharFormat(format);
}

I need to have the ability to use superscripts asnd subscripts in a QLineEdit in Qt 4.6. I know how to do superscripts and subscripts in a QTextEdit as seen below but I can't figure out how to do them in QLineEdit because the class doesn't contain a mergeCurrentCharFormat() function like QTextEdit does. Please help. Thanks

void MainWindow::superscriptFormat()
{
   QTextCharFormat format;
   format.setVerticalAlignment(QTextCharFormat::AlignSuperScript);
   if(ui->txtEdit->hasFocus())
      ui->txtEdit->mergeCurrentCharFormat(format);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

红衣飘飘貌似仙 2024-09-01 09:51:20

QLineEdit 并不是真正为此类事情而设计的,因为它是为简单的文本输入而设计的。不过,您有几个选择。最简单的方法是按照 Hostile Fork 的建议进行操作并使用 QTextEdit,并添加样式覆盖以不显示滚动条(我认为这会删除箭头)。更复杂的方法是继承 QLineEdit 并进行您自己的绘图,或者完全制作您自己的小部件,其外观与 QLineEdit 类似。

QLineEdit wasn't really made for this type of thing, as it was designed for simple text entry. You have a few options, however. The simplest one is to do as Hostile Fork suggested and use a QTextEdit, and add a style override to not show the scroll bar (which I assume would remove the arrows). The more complex one would be to either inherit QLineEdit and do your own drawing, or to make your own widget completely that appears similar to the QLineEdits do.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文