PDA

View Full Version : QTableWidget Delegate



aekilic
12th May 2009, 09:20
Dear All

We have a QTableWidget and delegates for columns. Problem we have is no matter how many rows we have in the last column when we hit the tab key the cursers goes to the (0,0) of the table, Is there any way to omit that?

wysota
12th May 2009, 09:43
Please provide a minimal compilable example reproducing the problem, I can't reproduce it myself.

aekilic
12th May 2009, 21:00
you could try this in designer,

create a qtablewidget ad some columns and rows, the last column and bottom row, it you press tab it will go to (0,0) What I want is the the curser will not move there?

Lykurg
12th May 2009, 21:48
Well, that is the default behavior, if the table is at the end and you press tab it jumps to the first cell. If you really want to change that, reimp keyPressEvent(), check if tab was pressed and the last cell is the current cell, if so do nothing, else call QTableView::keyPressEvent(event).

aekilic
13th May 2009, 16:56
I have this for the widget



if(qe->type() == QEvent::KeyPress)
{

QMessageBox::information(0, QString::fromUtf8("tab"), QString::fromUtf8("tab"));
QKeyEvent *ke = (QKeyEvent*)qe;
if(ke->key() == Qt::Key_Tab)
{


QMessageBox::information(0, QString::fromUtf8("tab2"), QString::fromUtf8("tab2"));
tableCekSenet->setTabKeyNavigation(false);
return true;
}

}


But I wasnt able to get the message for tab2

aekilic
13th May 2009, 18:41
I have just figure out someting,

Please try, create a qtablewidget with 3 row and 3 columns. When you come to 3rd row and 3 column if you double click into the cell and press tab after that you will go the 1st row and 1st column the curser will go like editing the cell, I had to avoid that? How could I do it?

wysota
13th May 2009, 18:48
But I wasnt able to get the message for tab2
I see you are using an event filter. On which widget did you install it?


I have just figure out someting,

Please try, create a qtablewidget with 3 row and 3 columns. When you come to 3rd row and 3 column if you double click into the cell and press tab after that you will go the 1st row and 1st column the curser will go like editing the cell, I had to avoid that? How could I do it?

Change the edit triggers for the view.

aekilic
13th May 2009, 19:06
how can do it?

Were you able to what I am doing?

Please check the attach, please see the 1.jpg after that when I press tab, 2.jpg occurs. What I want is in the 1.jpg when I press tab I want the curser to go on the 0,0 cell but not editing mode like picture 3 mode.

wysota
13th May 2009, 19:58
You may try providing your own item delegate that will not emit the default closeEditor() signal but will instead emit it with QAbstractItemDelegate::NoHint. See the docs for details.

aekilic
14th May 2009, 08:11
dear wysota

I really dont understand what you have said

wysota
14th May 2009, 10:00
Open Assistant and type in "closeEditor" in the index tab.

aekilic
15th May 2009, 10:12
Dear All

What i did is blow



QWidget *CekSenetDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &option,
const QModelIndex &index) const {

QComboBox *editor = new QComboBox(parent);

editor->addItem(QString::fromUtf8(""), "0");
while(...) editor->addItem(...);
editor->setSizeAdjustPolicy(QComboBox::AdjustToContents);
connect(editor, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor()));

return editor;
}

void CekSenetDelegate::commitAndCloseEditor()
{
QMessageBox::warning(0, QString::fromUtf8("zzzz"),
QString::fromUtf8("İzzzz"));

QComboBox *editor = qobject_cast<QComboBox *>(sender());
emit commitData(editor);
emit closeEditor(editor, QAbstractItemDelegate::NoHint);

}



I never get the message zzzz

spirit
15th May 2009, 10:21
I don;t see where you set


...
editor->setEditable(true);
...

at first. then QComboBox has not such signal editingFinished, but QLineEdit has.
so, you should write like this:


QWidget *CekSenetDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &option,
const QModelIndex &index) const {

QComboBox *editor = new QComboBox(parent);
editor->setEditable(true);
editor->addItem(QString::fromUtf8(""), "0");
while(...) editor->addItem(...);
editor->setSizeAdjustPolicy(QComboBox::AdjustToContents);
connect(editor->lineEdit(), SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor()));

return editor;
}