Results 1 to 6 of 6

Thread: Clicking Whitespace in a table

  1. #1

    Default Clicking Whitespace in a table

    Hi All,

    I've been trying to work out how to deselect all cells in a table, by selecting white space in the table.

    My table has a set height and width, and is initially empty, so theres a lot of white space. When I add a row and select it, I can't deselect it by clicking the whitespace below. Thats what I'm trying to solve.

    I'm using a QTableWidget as my table. Is there anyway to do that?

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Clicking Whitespace in a table

    Reimplement mousePressEvent() and clear selection if itemAt() returns 0 for event->pos(). Don't forget to call the base class implementation to keep it aware of mouse press events.
    J-P Nurmi

  3. #3

    Default Re: Clicking Whitespace in a table

    Awesome, thanks for the help jpn!

    I did what you said, and its nearly working . I added

    Qt Code:
    1. def mousePressEvent(self, event):
    2. if not self.table.itemAt(event.pos()):
    3. self.table.clearSelection()
    To copy to clipboard, switch view to plain text mode 

    It works when I click anywhere on the interface, but not on the whitespace of the table, or other widgets. Has that got something to do with calling the base class? I don't understand the last comment you made. Do I have to make the table aware of mouse events?
    Last edited by jpn; 11th March 2008 at 06:22. Reason: missing [code] tags

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Clicking Whitespace in a table

    Looks like you reimplemented mousePressEvent() of the widget which contains the table. Instead, you should have reimplemented mousePressEvent() of the table itself.
    J-P Nurmi

  5. #5

    Default Re: Clicking Whitespace in a table

    Hey again,

    I had to move on to other fixes, so I put this on hold for a while. I understand what you mean jpn, but how do I re-implement the mouse press event of the table. Has that got something to do with the signature?

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Clicking Whitespace in a table

    Subclass QTableWidget and reimplement it for the table. Just like you subclassed QWidget and reimplemented it for the window so far.
    J-P Nurmi

Similar Threads

  1. displaying any table on a qdatatable
    By Philip_Anselmo in forum Newbie
    Replies: 4
    Last Post: 9th May 2006, 22:12
  2. creating table plugin
    By mgurbuz in forum Qt Programming
    Replies: 3
    Last Post: 28th April 2006, 13:50

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.