Results 1 to 9 of 9

Thread: Disable an editable cell

  1. #1
    Join Date
    Mar 2008
    Posts
    57
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Disable an editable cell

    I have qtablewidget with delegates. If a cell does not receive a value, e.g. the cell is empty and the user tries to open its editor, it crashes? How do I avoid the crash? I would like to be able to disable the cell if there is no value.

  2. #2
    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: Disable an editable cell

    you can make value checking in createEditor of your delegate and if value is empty retun 0.

  3. #3
    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: Disable an editable cell

    What does the debugger say about the crash? Can you show us the backtrace?

    Anyway, you can disable editing a cell by returning proper flags from your model (i.e. don't return ItemIsEditable for the item).

  4. #4
    Join Date
    Mar 2008
    Posts
    57
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Disable an editable cell

    Sorry...my mistake...it does not crash...but the editor opens with the minimum value of the spinbox.

    ok...I set item->setFlags(Qt::ItemIsSelectable) to disable the cell if there is no value. It works, But...is it not possible to set item->setFlags(Qt::ItemIsEditable) if a value shows up later on? That does not work?

  5. #5
    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: Disable an editable cell

    You can change the flags at any time.

  6. #6
    Join Date
    Mar 2008
    Posts
    57
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Disable an editable cell

    Well...I am doing something wrong?

    This is the table constructor...
    Qt Code:
    1. .
    2. .
    3. .
    4. pItemTorque = new QTableWidgetItem;
    5. pItemTorque->setTextAlignment(Qt::AlignHCenter);
    6. setItem(ROW_TORQUE, SECOND_COLUMN, pItemTorque);
    7. .
    8. .
    9. .
    To copy to clipboard, switch view to plain text mode 

    ...and this is the method that is called to populate the cell...
    Qt Code:
    1. void PSetConfigurationTable::setTorque(QString torque)
    2. {
    3.  
    4. QTableWidgetItem *torqueItem = item( 0, 1 );
    5.  
    6. if(torque.isEmpty())
    7. {
    8.  
    9. torqueItem->setFlags(Qt::ItemIsSelectable);
    10.  
    11. }
    12. else
    13. {
    14.  
    15. torqueItem->setFlags(Qt::ItemIsEditable);
    16.  
    17. }
    18.  
    19. torqueItem->setData(Qt::EditRole, QVariant(torque));
    20.  
    21. }
    To copy to clipboard, switch view to plain text mode 

    It is ok if the cell is editable if a value is set. If a value is not set the cell is just selectable...and if a value comes along the setFlags(Qt::ItemIsEditable) does not work...in fact the app. goes down. What am i doing wrong?

  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: Disable an editable cell

    You probably want to set more than one flag at once...
    Qt Code:
    1. item->setFlags(Qt::ItemIsEnabled|Qt::ItemIsSelectable|Qt::ItemIsEditable);
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    Mar 2008
    Posts
    57
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Disable an editable cell

    I am not sure where and how the flags should be set? I think I have tried every combination of setflags for every state the parameter value can be in, but can't get it to work properly?

  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: Disable an editable cell

    What do you do, what do you get and what do you expect?

Similar Threads

  1. Word wrapping in a QTableWidget cell
    By jcooperddtd in forum Qt Programming
    Replies: 3
    Last Post: 1st May 2007, 03: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.