Results 1 to 2 of 2

Thread: Maximum Characters in Qtablewidgetitem

  1. #1
    Join Date
    Jul 2009
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Maximum Characters in Qtablewidgetitem

    Hi,

    I want to fix the maximum characters that a user can input in a qtablewidgetitem.

    I was thinking of validators, but I'm not sure how to do it.

    Any hints?

    Thanks

  2. #2
    Join Date
    May 2009
    Posts
    62
    Thanks
    2
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Maximum Characters in Qtablewidgetitem

    QTableWidget uses a QLineEdit to edit the contents of an item. The QLineEdit is provided by the QItemDelegate installed for every column. You can use QLineEdit::setMaxLength to fix the maximum number of characters.

    Do the following:
    1. Create a subclass of QItemDelegate.
    2. Override QItemDelegate::createEditor (see code below).
    3. Install your ItemDelegate in the QTableWidget using setItemDelegate , setItemDelegateForColumn, or setItemDelegateForRow as appropriate.


    Qt Code:
    1. virtual QWidget* MyItemDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index ) const
    2. {
    3. QLineEdit* lineEdit = new QLineEdit(parent);
    4. lineEdit->setMaxLength(80); // or whatever...
    5. return lineEdit;
    6. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QTableView + sorting + numbers & special characters
    By foggy-mind in forum Qt Programming
    Replies: 5
    Last Post: 4th June 2009, 11:11
  2. Axis's minimum and maximum
    By pankaj.patil in forum Qwt
    Replies: 4
    Last Post: 16th June 2008, 21:38
  3. Maximum number of characters in width
    By ralphmerridew in forum Qt Programming
    Replies: 3
    Last Post: 27th May 2008, 01:55
  4. Replies: 13
    Last Post: 10th October 2007, 15:38
  5. Problem at time compilation in traslation of language
    By thomasjoy in forum Qt Programming
    Replies: 3
    Last Post: 22nd May 2007, 14:18

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.