PDA

View Full Version : How can i have echomode in QtableView for password column?



WinterIsComing
8th July 2013, 15:16
In my administration window, i list a table (Qtableview) of existing users of the program. And operations for adding, editing or deleting users.

One of the columns in the table is "Password". Currently everyone ho has access to the admin window in my program, has enough rights so i'm not hiding passwords from anyone.

Except, there is one user called "admin" he is the pre-created user who cannot be deleted or modified by others. I want the password field to be invisible (****) for the row where the "admin" is listed. (only if the "admin" is not logged in).

I now you have echomode for QlineEdit, that is good for in the process when inserting a new user or editing. However, i don't know how to pass the echomode with the model?

For example, i have ordinary model wich has:


QVariant UsersModel::data(const QModelIndex &index, int role) const
{
...
if (!index.isValid())
return QVariant();

if (role == Qt::DisplayRole)
{
.....
switch(index.column())
{
case 0:
return object.strFirstName;
case 1:
return object.strLastName;
case 2:
return object.strLogin;
case 3:
return object.strPass; // how to set echomode::password (or: *****) ?
}
}



How can i have echomode in QtableView?

ChrisW67
8th July 2013, 22:59
You create a QStyledItemDelegate that you set on the column of passwords in the view (not the model, setItemDelegateForColumn()). When asked to create the editor (createEditor()) it should create a QLineEdit set to obscure the echo. You can have the delegate look at the value in another column before deciding whether to obscure the password.

WinterIsComing
11th July 2013, 11:09
thanks i will look into it and respond with the results