繁体   English   中英

Qt QPlainTextEdit背景

[英]Qt QPlainTextEdit background

我想更改QPlainTextEdit的背景颜色,我该怎么做?

修改纯文本编辑的调色板。 示例程序:

#include <QApplication>
#include <QPlainTextEdit>

int main(int argc, char* argv[])
{
  QApplication app(argc, argv);

  QPlainTextEdit edit;
  QPalette p = edit.palette();

  p.setColor(QPalette::Active, QPalette::Base, Qt::red);
  p.setColor(QPalette::Inactive, QPalette::Base, Qt::red);

  edit.setPalette(p);

  edit.show();
  return app.exec();
}

当然,替代你想要的任何颜色。

有点混乱,他们称之为角色而不是颜色/颜色。

https://doc.qt.io/qt-5/qwidget.html#setBackgroundRole

提示 - 如果找不到特定控件的功能,请单击show inherited members - 大多数常规设置都在qWidget中,这是在屏幕上绘制的eveything的基础。

如果QPlainTextEdit支持样式表,您可以这样做:

myPlainTextEdit->setStyleSheet("background-color: yellow");

要么

qApp->setStyleSheet("QPlainTextEdit {background-color: yellow}");

可能是你需要调用QPlainTextEdit::setBackgroundVisible(true)

要修改背景,您需要修改QPlainTextEdit的调色板并将背景设置为可见:

myPlainTextEdit->setPalette(QPalette(/*Select the constructor you need*/));
myPlainTextEdit->setBackgroundVisible(true);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM