Results 1 to 5 of 5

Thread: QTableView change color of current Cell

  1. #1
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default QTableView change color of current Cell

    Hi everybody,

    QT:4.1.1

    I have a Table View with some cells.
    Its possible to change the color of a cell by doble clicking it?And to change it again by leaving it?
    Think DigitalGasoline

  2. #2
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: QTableView change color of current Cell

    1) connect some slot to signal itemDoubleClicked ( QTableWidgetItem * item ) of your QTabLeWidget
    2) use catched QTableWidgetItem * item for setting bg color( method setBackgroundColor)
    a life without programming is like an empty bottle

  3. #3
    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: QTableView change color of current Cell

    Quote Originally Posted by zlatko
    1) connect some slot to signal itemDoubleClicked ( QTableWidgetItem * item ) of your QTabLeWidget
    2) use catched QTableWidgetItem * item for setting bg color( method setBackgroundColor)
    For a QTableView you would connect to signals like:
    void QAbstractItemView::doubleClicked ( const QModelIndex & index )
    void QAbstractItemView::entered ( const QModelIndex & index )


    I don't see any particular signal for leaving an item. But of course you can save row/col or a persistent index for the previously colourized cell and uncolourize during the entered signal of another item and possibly leave event of the whole table view..

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTableView change color of current Cell

    Quote Originally Posted by raphaelf
    Its possible to change the color of a cell by doble clicking it?And to change it again by leaving it?
    Double clicking? Or single clicking? For a single click it should be enough to set the QPalette::Highlight role for the pallete in your view. Otherwise you'll have to subclass the table view (or use an event filter, but for model based widgets it could be too complex).

  5. #5
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QTableView change color of current Cell

    Hi everybody,
    Thanks for replies..
    It looks to be not easy..

    I just would like to have a solution with colors like yellow or red, so that the user knows that he are in a dangerous process, like update a row..

    I will try to implement all 3 posted example...but i think it will be not easy
    Think DigitalGasoline

Similar Threads

  1. Distributing QT application for Mac OS
    By mb0 in forum Qt Programming
    Replies: 1
    Last Post: 31st May 2007, 18:59
  2. Replies: 15
    Last Post: 21st April 2007, 17:46

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.