Results 1 to 7 of 7

Thread: How to prevent QTableWidget from inserting a new row

  1. #1
    Join Date
    Apr 2011
    Posts
    13
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How to prevent QTableWidget from inserting a new row

    QTableWidget inserts a new row when Enter key is pressed in a blank cell.
    How can I suppress this behavior?
    Should I catch the enter-key event using an event filter?

  2. #2
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to prevent QTableWidget from inserting a new row

    Hmmm does it?
    That's interesting.

    You're sure you're not doing it somehow?

    Which Qt version you're using?

  3. #3
    Join Date
    Apr 2011
    Posts
    13
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to prevent QTableWidget from inserting a new row

    Hi, thank you for reply.

    I am using Qt 4.8.0 on Linux/X11.
    When I select a cell with a mouse click and press the enter key, a new row is inserted below the selected cell.
    Doesn't it be like this in your environment?

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to prevent QTableWidget from inserting a new row

    Linux, Qt 4.7.4 or Qt 4.8.0, this code
    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5. QApplication app(argc, argv);
    6. QTableWidget tw(5, 5);
    7. tw.show();
    8. return app.exec();
    9. }
    To copy to clipboard, switch view to plain text mode 
    Behaves as expected.

    Do you have an active push button elsewhere in the UI that adds a row?

  5. #5
    Join Date
    Apr 2011
    Posts
    13
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to prevent QTableWidget from inserting a new row

    Thank you for reply.
    Quote Originally Posted by ChrisW67 View Post
    Do you have an active push button elsewhere in the UI that adds a row?
    You've hit the nail on the head.
    I have several buttons on the table widget, and one of them right below the QTableWidget is connected to a slot that inserts a row.
    I found that the button is somehow also selected every time I clicked a cell in the table and the slot is called when the enter key is pressed after that.
    I don't know how this happens...

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to prevent QTableWidget from inserting a new row

    It will be related to the presence of default and auto-default buttons on the dialog. If you press Enter when not editing a cell of your table then one of the buttons will be triggered. When editing a cell the table should swallow the Enter keypress.

  7. The following user says thank you to ChrisW67 for this useful post:

    lain (29th March 2012)

  8. #7
    Join Date
    Apr 2011
    Posts
    13
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to prevent QTableWidget from inserting a new row

    Thanks for telling me about "default" and "autoDefaut" properties of a button.
    This may not be the best solution, but I worked around by turning off autoDefault property of all the buttons.

Similar Threads

  1. PyQt4 - Inserting data from array to QTableWidget
    By phosse1 in forum Qt Programming
    Replies: 1
    Last Post: 22nd December 2010, 20:20
  2. QTableWidget - inserting data
    By Tomasz in forum Newbie
    Replies: 1
    Last Post: 29th September 2010, 14:32
  3. Inserting Items in QTableWidget
    By Ma7moud El-Naggar in forum Newbie
    Replies: 1
    Last Post: 30th August 2010, 13:17
  4. Replies: 12
    Last Post: 28th April 2007, 20:25
  5. Problem inserting in QTableWidget
    By DPinLV in forum Qt Programming
    Replies: 2
    Last Post: 2nd August 2006, 00:10

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.