Results 1 to 13 of 13

Thread: QTableWidget Delegate

  1. #1
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default QTableWidget Delegate

    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?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTableWidget Delegate

    Please provide a minimal compilable example reproducing the problem, I can't reproduce it myself.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidget Delegate

    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?

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QTableWidget Delegate

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

  5. #5
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidget Delegate

    I have this for the widget

    Qt Code:
    1. if(qe->type() == QEvent::KeyPress)
    2. {
    3.  
    4. QMessageBox::information(0, QString::fromUtf8("tab"), QString::fromUtf8("tab"));
    5. QKeyEvent *ke = (QKeyEvent*)qe;
    6. if(ke->key() == Qt::Key_Tab)
    7. {
    8.  
    9.  
    10. QMessageBox::information(0, QString::fromUtf8("tab2"), QString::fromUtf8("tab2"));
    11. tableCekSenet->setTabKeyNavigation(false);
    12. return true;
    13. }
    14.  
    15. }
    To copy to clipboard, switch view to plain text mode 

    But I wasnt able to get the message for tab2

  6. #6
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidget Delegate

    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?

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTableWidget Delegate

    Quote Originally Posted by aekilic View Post
    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?

    Quote Originally Posted by aekilic View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidget Delegate

    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.
    Attached Images Attached Images
    • File Type: jpg 1.jpg (25.6 KB, 36 views)
    • File Type: jpg 2.jpg (24.9 KB, 22 views)
    • File Type: jpg 3.jpg (25.5 KB, 27 views)

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTableWidget Delegate

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidget Delegate

    dear wysota

    I really dont understand what you have said

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTableWidget Delegate

    Open Assistant and type in "closeEditor" in the index tab.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #12
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidget Delegate

    Dear All

    What i did is blow

    Qt Code:
    1. QWidget *CekSenetDelegate::createEditor(QWidget *parent,
    2. const QStyleOptionViewItem &option,
    3. const QModelIndex &index) const {
    4.  
    5. QComboBox *editor = new QComboBox(parent);
    6.  
    7. editor->addItem(QString::fromUtf8(""), "0");
    8. while(...) editor->addItem(...);
    9. editor->setSizeAdjustPolicy(QComboBox::AdjustToContents);
    10. connect(editor, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor()));
    11.  
    12. return editor;
    13. }
    14.  
    15. void CekSenetDelegate::commitAndCloseEditor()
    16. {
    17. QMessageBox::warning(0, QString::fromUtf8("zzzz"),
    18. QString::fromUtf8("İzzzz"));
    19.  
    20. QComboBox *editor = qobject_cast<QComboBox *>(sender());
    21. emit commitData(editor);
    22. emit closeEditor(editor, QAbstractItemDelegate::NoHint);
    23.  
    24. }
    To copy to clipboard, switch view to plain text mode 

    I never get the message zzzz

  13. #13
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableWidget Delegate

    I don;t see where you set
    Qt Code:
    1. ...
    2. editor->setEditable(true);
    3. ...
    To copy to clipboard, switch view to plain text mode 
    at first. then QComboBox has not such signal editingFinished, but QLineEdit has.
    so, you should write like this:
    Qt Code:
    1. QWidget *CekSenetDelegate::createEditor(QWidget *parent,
    2. const QStyleOptionViewItem &option,
    3. const QModelIndex &index) const {
    4.  
    5. QComboBox *editor = new QComboBox(parent);
    6. editor->setEditable(true);
    7. editor->addItem(QString::fromUtf8(""), "0");
    8. while(...) editor->addItem(...);
    9. editor->setSizeAdjustPolicy(QComboBox::AdjustToContents);
    10. connect(editor->lineEdit(), SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor()));
    11.  
    12. return editor;
    13. }
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

Similar Threads

  1. Delegate for a certain item?
    By somebody in forum Qt Programming
    Replies: 1
    Last Post: 18th August 2008, 22:55
  2. Again QTableWidget and QComboBox delegate
    By Aki-Matti in forum Qt Programming
    Replies: 2
    Last Post: 4th March 2008, 13:40
  3. QComboBox in QTableWidget : display troubles.
    By Nyphel in forum Qt Programming
    Replies: 2
    Last Post: 13th October 2007, 23:29
  4. QTableWidget editing question
    By Trasmeister in forum Qt Programming
    Replies: 1
    Last Post: 20th September 2006, 18:46
  5. Replies: 6
    Last Post: 5th March 2006, 21:05

Tags for this Thread

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.