我有一堆名为“e1”,“e2”,“e3”等的lineEdits。 我想设置相同的样式表对所有这些在一个循环中,没有实现代码QT/C++通过从变量中获取其名称来设置QObject的属性
ui->e1->setStyleSheet("background-color: white");
ui->e2->setStyleSheet("background-color: white");
ui->e3->setStyleSheet("background-color: white");
ui->e4->setStyleSheet("background-color: white");
ui->e5->setStyleSheet("background-color: white");
ui->e6->setStyleSheet("background-color: white");
,但这样的事情:
for (z=1; z<7; z=z+1)
{ui->e&z->setStyleSheet("background-color: white");}
也许有另一种方式的属性设置为一堆相似的物体?任何帮助表示感谢,提前谢谢!
一些原因我不得不使用Qt Disigner;(和事业恰克lineEdits的样式表是使lineEdit的背景红色以防输入错误的数据,所以这段代码是从清除背景到“默认”白色的按钮。 –
有状态的样式?[你可以用动态属性来做到这一点](http://doc.qt.io/ qt-5/stylesheet-examples.html#customizing-using-dynamic-properties)。在HTML/CSS中的等价物将是使用'.class-selectors',但尽管Qt样式表存在这种语法,但它意味着不同的东西。 – JesseTG