Results 1 to 2 of 2

Thread: How to make a QTableWidgetItem UnSelectable?

  1. #1
    Join Date
    Jul 2010
    Posts
    20
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default How to make a QTableWidgetItem UnSelectable?

    I want to implement a tablewidget , The items in it can be Selectable or UnSelectable but non-editable. i tried :

    1.
    Qt Code:
    1. self.setEditTriggers(QAbstractItemView.NoEditTriggers)
    To copy to clipboard, switch view to plain text mode 
    with
    Qt Code:
    1. self.item(row, col).setFlags(Qt.NoItemFlags)
    To copy to clipboard, switch view to plain text mode 
    not working

    2.
    Qt Code:
    1. self.setEditTriggers(QAbstractItemView.NoEditTriggers)
    To copy to clipboard, switch view to plain text mode 
    with
    Qt Code:
    1. onCellClicked(self,row,col):
    2. if item(row,col) is non-selectable:
    3. self.setCurrentCell(-1,-1)
    To copy to clipboard, switch view to plain text mode 
    works,but the selected background showed for a while
    3.
    Qt Code:
    1. self.setEditTriggers(QAbstractItemView.NoEditTriggers)
    To copy to clipboard, switch view to plain text mode 
    with
    Qt Code:
    1. onCellClicked(self,row,col):
    2. if item(row,col) is non-selectable:
    3. self.item(row,col).setSelected (False)
    To copy to clipboard, switch view to plain text mode 
    not working too.

    Overriding mousePressEvent may works, But is there any other method?

    Thx in advance and sry for my bad english.
    Last edited by vertusd; 5th January 2011 at 09:45.

  2. #2
    Join Date
    Feb 2010
    Location
    Wokingham, United Kingdom
    Posts
    36
    Thanks
    7
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to make a QTableWidgetItem UnSelectable?

    try setting the item flags before you put the item into the QTableWidget i.e.
    Qt Code:
    1. QTableWidgetItem *item = new QTableWidgetItem("item text");
    2. item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
    3. ui->tablewidget->setItem(row, col, item);
    To copy to clipboard, switch view to plain text mode 

    hope that works
    Last edited by janorcutt; 5th January 2011 at 11:48.

Similar Threads

  1. Replies: 6
    Last Post: 10th March 2011, 16:42
  2. Replies: 1
    Last Post: 15th December 2010, 13:20
  3. QTableWidgetItem Text
    By pytro in forum Qt Programming
    Replies: 2
    Last Post: 6th August 2007, 21:44
  4. Window OS make distclean && qmake && make one line
    By patrik08 in forum General Programming
    Replies: 4
    Last Post: 22nd March 2007, 10:43
  5. Im became fool with QTableWidgetItem
    By zorro68 in forum Qt Programming
    Replies: 3
    Last Post: 28th February 2007, 12:17

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
  •  
Qt is a trademark of The Qt Company.