Results 1 to 6 of 6

Thread: QTableWidget row selection

  1. #1
    Join Date
    Sep 2009
    Location
    Las Vegas, Nevada - USA
    Posts
    12
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default QTableWidget row selection

    I been dealing with this QTableWidget for several days, and got most of what I want except one simple thing.

    When I select on a row, it shows a box around the item column that I clicked on. I want to treat the row as a comlete selection as the table is a read only table. I know I am doing something increditable hard that should be simple.

    I haven't needed to post in over 2 weeks as I am learning, but I swear I have read every help line there is.

    Thanks.

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTableWidget row selection

    Doesn't QTableWidget inherit from QAbstractItemView, which has setSelectionBehavior?

    ie. obj->setSelectionBehavior(QAbstractItemView::SelectRow s);

    Don't just read the docs for the widget your using, you need to read the docs for the inherited classes too

    EDIT: Why is "SelectRows" all one word in the editor, but "SelectRow s" in the viewer?
    Last edited by squidge; 16th October 2009 at 23:46.

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QTableWidget row selection

    there are some posts about how to remove the focus rectangle. For an graphics item it would be
    Qt Code:
    1. QStyleOptionGraphicsItem *o = const_cast<QStyleOptionGraphicsItem*> (option);
    2. o->state &= ~QStyle::State_HasFocus;
    3. QGraphicsRectItem::paint(painter, o, widget);
    To copy to clipboard, switch view to plain text mode 
    For a table widget it is similar and you have to alter the QItemDelegate::paint() method and set your custom delegate to the table. Try to achieve that. If you have trouble (and it is kind of hard if you just started with Qt, but try it) ask again.

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QTableWidget row selection

    Quote Originally Posted by fatjuicymole View Post
    Don't just read the docs for the widget your using, you need to read the docs for the inherited classes too
    But he is talking about the dotted border around the item he has clicked not about how to select a row.

    EDIT: Why is "SelectRows" all one word in the editor, but "SelectRow s" in the viewer?
    If you would use the CODE tags, it wouldn't occur:

    Qt Code:
    1. obj->setSelectionBehavior(QAbstractItemView::SelectRows);
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Sep 2009
    Location
    Las Vegas, Nevada - USA
    Posts
    12
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableWidget row selection

    Lykurg:

    Thank you and I will try this. You are correct that I am trying to hide the dotted lines.

    Row selection isn't an issue, the fact that you have to override a paint when row selection is already set seem like a bug. But most likely there are hundreds of good reasons for this.

    Thank again for you help, and I will post if I was sucessful or not.

  6. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QTableWidget row selection

    Quote Originally Posted by BingoMaster View Post
    the fact that you have to override a paint when row selection is already set seem like a bug.
    No it's not. Selection and focus are two different things. And to indicate which item inside a multi-item-selection is "selected"/focused you need that dotted line. So in normal case it's perfect. Your case is special, because you don't need the information which item is focused. So small reimplement and all is fine. I've done that a lot of times myself...

Similar Threads

  1. QTableWidget, selection problem
    By stella1016 in forum Qt Programming
    Replies: 2
    Last Post: 6th October 2009, 15:49
  2. Selection in QTableWidget
    By Nippler in forum Qt Programming
    Replies: 3
    Last Post: 30th April 2008, 08:32
  3. Dragging mouse selection in QTableWidget
    By yartov in forum Qt Programming
    Replies: 1
    Last Post: 12th April 2008, 15:03
  4. Selection of cell with QWidget in QTableWidget
    By Tamara in forum Qt Programming
    Replies: 7
    Last Post: 17th February 2007, 14:11
  5. QTableWidget (resizing rows, turning off selection, etc.)
    By kiss-o-matic in forum Qt Programming
    Replies: 6
    Last Post: 11th January 2007, 01: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.