crawling qtableview ctrl-c ctrl-v

git-svn-id: svn://192.168.0.12/source@136 8346c931-da38-4b9b-9d4c-e48b93cbd075
This commit is contained in:
admin
2015-06-01 06:47:08 +00:00
parent e30b1fc341
commit 685b1f3623
3 changed files with 41 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
#include "stable.h"
#include <QDebug>
STable::STable()
{
@@ -10,3 +10,32 @@ STable::~STable()
}
void STable::keyPressEvent(QKeyEvent* event)
{
// If Ctrl-C typed
if (event->key() == Qt::Key_C && (event->modifiers() & Qt::ControlModifier))
Copy();
}
void STable::Copy()
{
QModelIndexList cells = selectedIndexes();
//qSort(cells);
QString text;
int currentRow = 0;
foreach (const QModelIndex& cell, cells)
{
if (text.length() == 0)
{
}
else if (cell.row() != currentRow)
text += '\n';
else
text += '\t';
currentRow = cell.row();
text += cell.data().toString();
}
QApplication::clipboard()->setText(text);
}

View File

@@ -2,13 +2,20 @@
#define STABLE_H
#include <QTableView>
#include <QKeyEvent>
#include <QApplication>
#include <QClipboard>
class STable : public QTableView
{
//Q_OBJECT
public:
STable();
~STable();
public:
void keyPressEvent(QKeyEvent* event);
void Copy();
};
#endif // STABLE_H

View File

@@ -12,6 +12,7 @@
#include <QFile>
#include <QStack>
#include <QFileDialog>
#include "stable.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
@@ -278,7 +279,8 @@ QGroupBox *Widget::setCrawlingWidgets()
}
{
m_ptableCrawling = new QTableView;
//m_ptableCrawling = new QTableView;
m_ptableCrawling = new STable;
m_ptableCrawling->setModel(m_pmodelCrawling);
m_ptableCrawling->setSelectionBehavior(QAbstractItemView::SelectRows);
m_ptableCrawling->setSelectionMode(QAbstractItemView::ContiguousSelection);