Results 1 to 2 of 2

Thread: Navigate through QTableWidget

  1. #1
    Join Date
    Oct 2007
    Posts
    39
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Exclamation Navigate through QTableWidget

    Hi All,

    I have encountered a small problem in QTableWiget.

    I want to navigate through table widget created programatically on Windows.
    Some of the items in table are non-editable and flags are set as

    Qt Code:
    1. QTableWigetItem* item = new QTableWidgetItem(str);
    2. qTableWiget->setItem(row, column, item);
    3. item->setFlags(item->flags() & (~Qt::ItemIsEditable));
    To copy to clipboard, switch view to plain text mode 

    I have intialize the table item with default properties as gets set in designer.
    Qt Code:
    1. qTableWiget->setTabKeyNavigation(true);
    2. qTableWiget->setAutoScroll(true);
    3. qTableWiget->setHorizontalScrollMode(QAbstractItemView::ScrollPerItem);
    4. qTableWiget->setVerticalScrollMode(QAbstractItemView::ScrollPerItem);
    5. qTableWiget->setSelectionMode(QAbstractItemView::ExtendedSelection);
    6. qTableWiget->setEditTriggers(QAbstractItemView::AnyKeyPressed |
    7. QAbstractItemView::DoubleClicked | QAbstractItemView::EditKeyPressed);
    To copy to clipboard, switch view to plain text mode 

    When I clicked on any of the item, it gets selected.
    But when I use arrow keys or tab key, no other item gets selected.

    Please let me know your suggestions on it.
    Darshan

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Navigate through QTableWidget

    Note the existence of two different concepts: selection and "current item". These are independent.
    The selection is what you know (blue background), the current is a rather hard to see dotted rectangle.

    Clicking selects the item (and also makes it current). Note that often the whole row is selected, but only one cell of it is current.

    With the arrow keys you usually move the current item, not the selection.


    If you insist on being able to do an extended selection, there is no way around that behaviour: how would you select rows 1 and 3 (with keyboard only) if hitting arrow keys moved the selection=?
    If single selection should suffice, try QAbstractItemView::SingleSelection as selection mode. Maybe current and selection are held in sync then.

    HTH

Similar Threads

  1. QComboBox in QTableWidget : display troubles.
    By Nyphel in forum Qt Programming
    Replies: 2
    Last Post: 13th October 2007, 23:29
  2. Select columns from a QTableWidget
    By toglez in forum Qt Programming
    Replies: 10
    Last Post: 7th October 2007, 15:15
  3. QTableWidget (resizing rows, turning off selection, etc.)
    By kiss-o-matic in forum Qt Programming
    Replies: 6
    Last Post: 11th January 2007, 01:57
  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

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.