QT控件通过setProperty设置属性显示内容

  • QLineEdit
    设置其text属性
QLineEdit *edit = new QLineEdit(this);
edit->setProperty("text","hello");
  • QPlainTextEdit
    设置其plainText属性
QPlainTextEdit *edit = new QPlainTextEdit(this);
edit->setProperty("plainText","hello");
  • QTextEdit
QTextEdit *edit = new QTextEdit(this);
edit->setProperty("html","hello");
  • QComboBox
QComboBox *box = new QComboBox(this);
box->setProperty("currentText","hello");//前提下拉框中本就有这一项内容
  • QTimeEdit
QTimeEdit *edit = new QTimeEdit(this);
edit->setProperty("time","10:00:00");
  • QDateEdit
QDateEdit *edit = new QDateEdit(this);
edit->setProperty("data", "2020-10-10");
  • QDataTimeEdit
QDataTimeEdit *edit = new QDataTimeEdit(this);
edit->setProperty("dataTime","2020-10-10 10:00:00");

这些属性名可以在设计师中看到,其中"placeholderText"属性是当控件没有内容显示时,则会显示这个属性设置的内容作为控件背景

你可能感兴趣的:(QT笔记)