我有表(由 QTableWidget 创建)。
我的表有 3 列
# | user | pass
用户和密码中的文本是可见的,即“用户”、“密码”
我想在传递中隐藏文本,例如:
"********" < means "password"
在 QLineEdit 中有一个名为“echomode”的好选项,但它仅适用于 QLineEdit。
我可以手动替换 * 的文本,但是我以后如何从表格(在类里面)读取这段文本?
比**更好的是点。 (如 echomode -> 密码)
问候
最佳答案
我会将表项文本设置为"*****"
,并将真实密码存储为具有特定作用的项数据。例如:
// Get the password item of first row
QTableWidgetItem *passwordItem = tableWidget->item(0, 2);
passwordItem->setText("*****");
passwordItem->setData(Qt::UserRole, "the_actual_password");
可以用类似的方式提取实际密码:
QString actualPassword = passwordItem->data(Qt::UserRole).toString();
关于c++ - 在 QtableWidget 中将列中的文本隐藏为密码点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25069887/