• 9475阅读
  • 9回复

如何在 选中 QListView 中的某一项时,进行某一个操作 [复制链接]

上一主题 下一主题
离线tsuibin
 

只看楼主 倒序阅读 楼主  发表于: 2009-10-15
— 本帖被 XChinux 从 General Qt Programming 移动到本区(2011-01-02) —

例如,当选中 QListView 中的 music.mp3 ,这个时候就调用播放器播放 ?
选中 QListView 中的 picture.gif 这个时候就调用图片浏览程序 ?

离线jorneyr

只看该作者 1楼 发表于: 2009-10-15
取得你选中的项的文本, 然后分析他的名字与后缀, 再用相应的程序打开.
离线tsuibin

只看该作者 2楼 发表于: 2009-10-15
引用第1楼jorneyr于2009-10-15 14:20发表的  :
取得你选中的项的文本, 然后分析他的名字与后缀, 再用相应的程序打开.



你好,我现在就是想在选中的出发某一个事件,我不知道这儿可以用的有什么事件?
selected event ?
离线haulm

只看该作者 3楼 发表于: 2009-10-15
只要判定QListView当前Model的currentIndex所指向的行列数值就可以了。
离线guobinzi
只看该作者 4楼 发表于: 2009-10-15
可以调用currentItem()得到当前Item的指针,不知道对不对?
离线haulm

只看该作者 5楼 发表于: 2009-10-15
我没用过currentItem,但方法肯定是一样的,得到临时选中的表单项,然后用鼠标事件进行触发,比如双击,你在双击事件中从currentitem或currentIndex中得到参数,然后根据参数调用其它程序或是代码进行操做。
离线tsuibin

只看该作者 6楼 发表于: 2009-10-15
I have solved this problem, qt has a clicked signal  function that  emitted when a mouse button is clicked. The item the mouse was clicked on is specified by index. The signal is only emitted when the index is valid.

connect(ui->listView_Group,SIGNAL(clicked(const QModelIndex &)),this,SLOT(selectionChanged(const QModelIndex &)));

void MusicSettingsWidget::selectionChanged(const QModelIndex & index)
{
    if ( index.data().toString() != "all music" ){
        musicSettings4a6ConfigFile->beginGroup("GroupList");
        QStringList musicList;
        musicList << musicSettings4a6ConfigFile->value(index.data().toString()).toString().split(";",QString::SkipEmptyParts);
        musicSettings4a6ConfigFile->endGroup();
        mp3ListModel->setStringList(musicList);
        ui->listView->setModel(mp3ListModel);
        ui->listView->selectAll();
    }else{
        mp3ListInit();
    }
}
离线tsuibin

只看该作者 7楼 发表于: 2009-10-21
现在有一个问题是
我的设备没有鼠标,没有clicked信号
只能通过 移动光标健来选择
但是移动光标键 没有信号
也就是说
我只使用QlistView (单选模式)用光标上下移动的时候 没有任何事件 ,我希望qt能支持这个事件!
离线tsuibin

只看该作者 8楼 发表于: 2009-10-21
我找到了一种更好的方式

    connect(selectionGroupModel,\
            SIGNAL(currentRowChanged( const QModelIndex & , const QModelIndex &  )),\
            this,\
            SLOT(selectionChanged( const QModelIndex & , const QModelIndex &  )));

这样在没有鼠标的时候也可以触发
离线jorneyr

只看该作者 9楼 发表于: 2009-10-21
currentIndexChanged
快速回复
限100 字节
 
上一个 下一个