• 5430阅读
  • 1回复

QListView里面怎么对文件或该文件夹实现重命名功能? [复制链接]

上一主题 下一主题
离线ch19860304
 
只看楼主 正序阅读 楼主  发表于: 2009-06-14
— 本帖被 XChinux 从 General Qt Programming 移动到本区(2011-01-02) —
我想实现这样一个功能:对着文件/文件夹右键单击,则文件/文件夹处于重命名状态,然后输入新的文件名,输完后,再右键一下,重命名成功。我是这样做的,但不对,提示错误:editing failed
    这个功能应该怎么做呀?

Imagewindow::Imagewindow()  //构造函数
{
    model = new QDirModel ;
    list = new QListView(this);
    list->setViewMode(QListView::IconMode);
    list->setModel(model);

    connect(list,SIGNAL(clicked(const QModelIndex &) ),this,SLOT(rename(const QModelIndex &))) ;   //clicked是专指右键单击吗?
}
    

void Imagewindow::rename(const QModelIndex &index)
{
    
     list->setCurrentIndex(index);
     list->edit (index ) ;
    list->update (index ) ;
    //如何表示:再右键一下,重命名成功
}
离线gvim
只看该作者 1楼 发表于: 2009-06-14
QDirModel的文档里提到
readOnly : bool
This property holds whether the directory model allows writing to the file system.
If this property is set to false, the directory model will allow renaming, copying and deleting of files and directories.
This property is true by default
Access functions:
bool isReadOnly () const
void setReadOnly ( bool enable )

是不是上面的原因,默认只读,调用setReadOnly(false)试试看。
Qt,Qt! 分享Cute之Qt体验
欢迎访问 http://www.cuteqt.com
欢迎订阅 http://www.cuteqt.com/?feed=rss2

快速回复
限100 字节
 
上一个 下一个