1. 使用qss文件設置全部
//禁用狀態
QLineEdit:disabled{
color: #000000;
background:#0000ff;
}
//編輯狀態
QLineEdit:enabled{
color: #000000;
background:#ff0000;
}
2. 使用setStyleSheet()函數設置
m_mainwindow->setStyleSheet("QLineEdit:enabled{color: #000000;background:#ff000000;}");
参考:
(1) Qt Style Sheets Examples
https://doc.qt.io/qt-6/stylesheet-examples.html#customizing-qlineedit
本文详细介绍了如何使用QSS样式文件为Qt中的QLineEdit控件设置不同状态下的颜色和背景,包括禁用状态和编辑状态,并通过setStyleSheet()函数实现实例。参考了Qt官方样例,适用于前端开发者进行UI定制。
2万+

被折叠的 条评论
为什么被折叠?



