PDA

View Full Version : QTableWidgetItem editing problem



fmariusd
3rd September 2009, 08:47
i have a QTableWidget and i want to edit his items

i use a QItemDelegate (it) and i extract the item editor

like this Widget * w= it->createEditor(ui.TableWidget,styleIt,ind);

lineEdit=qobject_cast(w);

and i get the lineEdit

the i set it->setEditorData(auxLine,ind); // ind is a QModelIndex from the QTableWidget

but when i move cursor in the QtableWidgetItem(in the lineEdit ) and then i sent some chars from another widget[ i emit a signal which sends the char] and use[ and catcht it in a slot and use lineEdit-> insert( text) to insert it ] it doesn't works as it should it inserts only at the end of the text .... not where the cursor is

Thanks

yogeshgokul
3rd September 2009, 09:06
it doesn't works as it should it inserts only at the end of the text .... not where the cursor is
You can manually move the cursor to end using. ;)

QLineEdit::end ( bool )
Then insert the text.

fmariusd
3rd September 2009, 09:13
but i want to insert text also somewhere in the middle not only at the end ...

yogeshgokul
3rd September 2009, 09:16
Store the cursor position in a variable. Use this position when you want to insert text in between text. And when you wanna insert at the end use QLineEdit::end(bool);

fmariusd
3rd September 2009, 09:29
i connect :

connect(auxLine,SIGNAL(cursorPositionChanged ( int, int ) ),this,SLOT(cursorPosChanged(int,int)) );

and when i move the cursor with my mouse the signal is not emited so i cant get the position

and i also shouldn't store because if everything works fine auxLine.insert will insert where the cursor is ...

it's like when i create the editor and after when i move the cursor my auxLine doesnt get al the information like cursor position or selection
it 's like it is not connected or the same with the editor from my QTableWidgetItem

Thanks.

faldzip
3rd September 2009, 12:36
but what do you want to achieve? you want to have line edit for editing items somewhere else than in you QTableWidget? Where do you create that editor? Can show us some compilable example and/or some screenshot?

fmariusd
3rd September 2009, 13:46
........
QAbstractItemModel* model=ui.futuresTableWidget->model();


ind= model->index(row,col);

QWidget *w =0;

if(it==0) it=dynamic_cast<QDrvAbstractItemDelegate*>ui.futuresTableWidget->itemDelegate());

QStyleOptionViewItem styleIt;
if(it!=0) w=it->createEditor(ui.futuresTableWidget,styleIt,ind);

auxLine=qobject_cast<QLineEdit*> (w);
it->setEditorData(auxLine,ind);

connect(auxLine,SIGNAL(cursorPositionChanged ( int, int ) ),this,SLOT(cursorPosChanged(int,int)) );

numPad->setWindowModality(Qt::WindowModal);
numPad->show();
numPad->raise();
........



I use auxLine to manage the text that i send from my numPad which is another widget from that i send numbers to the tablewidget and i want to insert the numbers where the
cursor is

the thing is when i send a number the qtablewidget item turns gray and it inserts items only at its end i dont know if this is relevant :p

//slot // numPad emits a signal sendText(t); and sends the text here
void catchText(QString text)
{
auxLine.insert(text);
}

faldzip
3rd September 2009, 14:23
... couldn't get the idea. Can you provide compilable example? Or at least some sreenshot?
P.S. and use CODE tags for code.

fmariusd
4th September 2009, 09:10
i think it should be pretty clear
i want to edit the QtableWidgetItem like a QlineEdit ,and to use the insert function of QlineEdit and to insert text anywhere where i place the cursor , so if someone knows how to do that....
Thanks