Results 1 to 9 of 9

Thread: QTableWidgetItem editing problem

  1. #1
    Join Date
    Jul 2008
    Posts
    26
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Question QTableWidgetItem editing problem

    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
    Last edited by fmariusd; 3rd September 2009 at 07:52.

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableWidgetItem editing problem

    Quote Originally Posted by fmariusd View Post
    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.
    Qt Code:
    1. QLineEdit::end ( bool )
    To copy to clipboard, switch view to plain text mode 
    Then insert the text.

  3. #3
    Join Date
    Jul 2008
    Posts
    26
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: QTableWidgetItem editing problem

    but i want to insert text also somewhere in the middle not only at the end ...

  4. #4
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableWidgetItem editing problem

    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);

  5. #5
    Join Date
    Jul 2008
    Posts
    26
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Exclamation Re: QTableWidgetItem editing problem

    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.
    Last edited by fmariusd; 3rd September 2009 at 10:07.

  6. #6
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidgetItem editing problem

    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?
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  7. #7
    Join Date
    Jul 2008
    Posts
    26
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: QTableWidgetItem editing problem

    ........
    QAbstractItemModel* model=ui.futuresTableWidget->model();


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

    QWidget *w =0;

    if(it==0) it=dynamic_cast<QDrvAbstractItemDelegate*>ui.futur esTableWidget->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

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

  8. #8
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidgetItem editing problem

    ... couldn't get the idea. Can you provide compilable example? Or at least some sreenshot?
    P.S. and use CODE tags for code.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  9. #9
    Join Date
    Jul 2008
    Posts
    26
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: QTableWidgetItem editing problem

    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
    Last edited by fmariusd; 4th September 2009 at 08:16.

Similar Threads

  1. Steps in solving a programming problem?
    By triperzonak in forum General Programming
    Replies: 8
    Last Post: 5th August 2008, 08:47
  2. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  3. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 14:08
  4. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.