Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Qt QPlainTextEdit背景_C++_Qt - Fatal编程技术网

C++ Qt QPlainTextEdit背景

C++ Qt QPlainTextEdit背景,c++,qt,C++,Qt,我想更改QPlainTextEdit的背景色,我该怎么做?有点令人困惑,他们称之为角色,而不是颜色/颜色 提示-如果您找不到特定控件的函数,请单击“显示继承成员”-大多数常规设置在qWidget中,这是屏幕上绘制的所有内容的基础。可能需要调用QPlainTextEdit::setBackgroundVisible(true),以便修改背景,您需要修改QPlainTextEdit的设置并将背景设置为可见: myPlainTextEdit->setPalette(QPalette(/*Sel

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

有点令人困惑,他们称之为角色,而不是颜色/颜色


提示-如果您找不到特定控件的函数,请单击“显示继承成员”-大多数常规设置在qWidget中,这是屏幕上绘制的所有内容的基础。

可能需要调用
QPlainTextEdit::setBackgroundVisible(true)
,以便修改背景,您需要修改QPlainTextEdit的设置并将背景设置为可见:

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

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

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


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

#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();
}
#包括
#包括
int main(int argc,char*argv[])
{
QApplication应用程序(argc、argv);
QPlainTextEdit编辑;
QPalette p=edit.palete();
p、 setColor(qpalete::Active,qpalete::Base,Qt::red);
p、 setColor(Qpalete::Inactive,Qpalete::Base,Qt::red);
编辑设置调色板(p);
edit.show();
返回app.exec();
}

当然,可以替换您想要的任何颜色。

没有使用过它,但请参阅此线程注意,使用此方法,将样式表应用于父级或控件本身将禁用此调色板。刚才有一些有趣的故障排除:)很高兴知道,谢谢!我还没有使用过样式表,所以感谢您的提前通知。请注意,这也会影响滚动条的颜色,这可能不是您想要的颜色。
#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();
}