Results 1 to 13 of 13

Thread: Disable or lock a QTableWidget

  1. #1
    Join Date
    Jun 2009
    Location
    México
    Posts
    20
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Disable or lock a QTableWidget

    Hi i'm working with a QTableWidget and want to disable or lock the edition of it. I know that a QTableView would do the trick, but i'm working with an open source project that has this "issue", because this table is big, it would take me a lot of time to start working with a QTableView. THANKS IN ADVANCE

  2. The following user says thank you to grub87 for this useful post:

    rawfool (20th April 2012)

  3. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Disable or lock a QTableWidget

    The most straight forward way, for the whole view:

    A bit more tedious way, adjusting the flags for individual items:
    J-P Nurmi

  4. The following user says thank you to jpn for this useful post:

    rawfool (20th April 2012)

  5. #3
    Join Date
    Jun 2009
    Location
    México
    Posts
    20
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Disable or lock a QTableWidget

    Hi thanks for your advice, but i don't know how to implement your answers could you give a head start on that please.

  6. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Disable or lock a QTableWidget

    What did you try so far?
    J-P Nurmi

  7. #5
    Join Date
    Jun 2009
    Location
    México
    Posts
    20
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Cool Re: Disable or lock a QTableWidget

    I thought i would be a property or function of my QTableWdiget object, for example:

    Qt Code:
    1. object->setEditTriggers(); //This tells me that inside the () goes a EditTriggers
    2. object->editTriggers();
    To copy to clipboard, switch view to plain text mode 

  8. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Disable or lock a QTableWidget

    Yes, it is a property. There is a getter that returns the current edit triggers in use, and there is a setter which you can use to change the edit triggers. Don't you think the setter would perhaps take a parameter, like suggested by your compiler? Not to be rude, but perhaps it's time to get back to your favourite C++ book for a while?

    PS. Here's the link to the documentation once more, because the first one seemed to be broken: QAbstractItemView::editTriggers
    J-P Nurmi

  9. #7
    Join Date
    Jun 2009
    Location
    México
    Posts
    20
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Disable or lock a QTableWidget

    Yes every object has a getter and a setter, the setter obviously needs a parameter, but i was refering to how you put the EditTriggers, i put it like this:

    Qt Code:
    1. ui.diariostableWidget->setEditTriggers(QAbstractItemView::EditTriggers(0));
    To copy to clipboard, switch view to plain text mode 

    But it doesn't work.

  10. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Disable or lock a QTableWidget

    That should work, but for better readability (and safer code) you should use the corresponding enum value called "no edit triggers".
    J-P Nurmi

  11. #9
    Join Date
    Jun 2009
    Location
    México
    Posts
    20
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Disable or lock a QTableWidget

    Hi again, i tried to use the NoEditTriggers like this but it doesn work either:

    Qt Code:
    1. ui.diariostableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
    To copy to clipboard, switch view to plain text mode 

  12. #10
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Disable or lock a QTableWidget

    But what do you mean by "doesn't work"? Please try to be more specific.
    J-P Nurmi

  13. #11
    Join Date
    Jun 2009
    Location
    México
    Posts
    20
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Disable or lock a QTableWidget

    I can still edit the items of the table

  14. #12
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Disable or lock a QTableWidget

    Works fine for me:
    Qt Code:
    1. // main.cpp
    2. #include <QtGui>
    3.  
    4. int main(int argc, char* argv[])
    5. {
    6. QApplication app(argc, argv);
    7. QTableWidget table(4, 4);
    8. // uncomment the following line and the table can no more be edited:
    9. // table.setEditTriggers(QAbstractItemView::NoEditTriggers);
    10. table.show();
    11. return app.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  15. The following user says thank you to jpn for this useful post:

    rawfool (20th April 2012)

  16. #13
    Join Date
    Jun 2009
    Location
    México
    Posts
    20
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Disable or lock a QTableWidget

    I think it doesn't work because in the part of the options of tha visual form in editTriggers the options of editing with double click was checked, i noticed the existance of this option until now , that's why anything i put in the .cpp didn't work. THANKS FOR ALL THE HELP!!!

Similar Threads

  1. QTableWidget: Disable 'snapping' to rows and columns?
    By PolyVox in forum Qt Programming
    Replies: 2
    Last Post: 8th October 2008, 20:04
  2. QComboBox in QTableWidget : display troubles.
    By Nyphel in forum Qt Programming
    Replies: 2
    Last Post: 13th October 2007, 23:29
  3. QTableWidget issues
    By Djony in forum Qt Programming
    Replies: 42
    Last Post: 19th December 2006, 23:27
  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.