我有有"\n"中有一个简单的字符串.它应该写入文件.例如:
var s = new StringBuilder();
s.Append("hello");
s.Append("\n");
s.Append("betty");
s.Append("is");
s.Append("my");
s.Append("\n");
s.Append("name");
string str = s.ToString();
Console.WriteLine(str);
Run Code Online (Sandbox Code Playgroud)
此字符串按预期打印:
hello bettyismy name
现在,当我尝试使用下面写这个字符串的文件:
var w = new StreamWriter(crcFilePath);
w.WriteLine(crcString);
w.Close();
Run Code Online (Sandbox Code Playgroud)
该文件的内容是:
hellobettyismyname
任何想法,为什么它忽略了字符串中的\n.
我有 QTreeView 和 QAbstractItemModel。一些特定的列应该有用户定义的复选框。我通过重写 QAbstractItemModel::data() 函数并发送 Qt::CheckStateRole 角色的检查状态来完成此操作,如代码中所示。
我收到了复选框,并且能够成功选中和取消选中它们。但要求是自定义其中一些复选框。基本上我需要通过任何方法将某些复选框与其他复选框区分开来,例如:用蓝色填充复选框、使复选框的边界为蓝色或任何其他方法。但我不确定如何更改复选框样式,因为我正在通过模型创建复选框。
QVariant MyModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
if (role == Qt::CheckStateRole && index.column() == COLUMN_WITH_CHECKBOX)
{
//return Qt::Checked or Qt::Unchecked here
}
//...
}
bool MyModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (!index.isValid())
return false;
if (role == Qt::CheckStateRole)
{
if ((Qt::CheckState)value.toInt() == Qt::Checked)
{
//user has checked item
return true;
}
else
{
//user has unchecked item
return true;
}
}
return …Run Code Online (Sandbox Code Playgroud)