Qt QPlainTextEdit background

前端 未结 5 935
Happy的楠姐
Happy的楠姐 2021-01-04 20:29

I want to change the background color of a QPlainTextEdit, how do I do this?

5条回答
  •  一生所求
    2021-01-04 21:10

    Modify the palette of your plain text edit. Sample program:

    #include 
    #include 
    
    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();
    }
    

    Substitute whatever color you want, of course.

提交回复
热议问题