Something very strange is happening... During my testing for the sollutions given above I came accross the following:
I have written some testcode as shown below . If you run this, you can see that renaming seems to be already implemented in QT and all you have to do is catch the itemRenamed.... I have never seen this before, but it seems to work fine! The connection below makes sure you can do whathever you want when an item is renamed...
mylistview.h
#ifndef mylistview_h
#define mylistview_h
#include <qlistview.h>
#include <iostream>
{
Q_OBJECT
public:
MyListView
(QWidget* parent
= 0,
const char* name
= 0, WFlags f
=0);
public slots:
void slotTestRename();
};
#endif
#ifndef mylistview_h
#define mylistview_h
#include <qlistview.h>
#include <iostream>
class MyListView : public QListView
{
Q_OBJECT
public:
MyListView(QWidget* parent = 0, const char* name = 0, WFlags f =0);
public slots:
void slotTestRename();
};
#endif
To copy to clipboard, switch view to plain text mode
mylistview.cpp
#include "mylistview.h"
MyListView
::MyListView(QWidget* parent,
const char* name, WFlags f
) {
connect(this, SIGNAL(itemRenamed(QListViewItem* , int)), this, SLOT(slotTestRename()));
}
void MyListView::slotTestRename()
{
std::cout << "RENAMED " << std::endl;
}
#include "mylistview.h"
MyListView::MyListView(QWidget* parent, const char* name, WFlags f)
: QListView(parent, name, f)
{
connect(this, SIGNAL(itemRenamed(QListViewItem* , int)), this, SLOT(slotTestRename()));
}
void MyListView::slotTestRename()
{
std::cout << "RENAMED " << std::endl;
}
To copy to clipboard, switch view to plain text mode
mainfile:
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <qapplication.h>
#include <mylistview.h>
int main(int argc, char *argv[])
{
MyListView* listview = new MyListView();
listview->addColumn("testcolumn");
a.setMainWidget(listview);
QListViewItem* item = new QListViewItem(listview);
item->setText(0, "trial");
item->setRenameEnabled(0, true);
listview->show();
//myMainWindow->showMaximized();
return a.exec();
}
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <qapplication.h>
#include <mylistview.h>
int main(int argc, char *argv[])
{
QApplication a(argc,argv);
MyListView* listview = new MyListView();
listview->addColumn("testcolumn");
a.setMainWidget(listview);
QListViewItem* item = new QListViewItem(listview);
item->setText(0, "trial");
item->setRenameEnabled(0, true);
listview->show();
//myMainWindow->showMaximized();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks