Results 1 to 13 of 13

Thread: how to enable hot spotting in QTableWidget.

  1. #1
    Join Date
    May 2009
    Posts
    31
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default how to enable hot spotting in QTableWidget.

    Hi

    I am pretty new to Qt and using Qt 4.4.3 over linux. I am building an application where i am displaying the grid data in QtableWidget.
    My application demands when ever a mouse pointer comes over a cell in QTableWidget some tool tip ( for the cell) should be displayed. Each row of table is having a unique set of User record. So i can achieve the same by adding a slot on signal QTableWidget::cellEntered(int,int). But for that i need to know the cell position i.e row,col. Which QT retrieves for signal "cellEntered()". So i wanted to know is there any way to get this row-col position from this signal?

    Thanks

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

    Default Re: how to enable hot spotting in QTableWidget.

    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    May 2009
    Posts
    31
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to enable hot spotting in QTableWidget.

    hey thnx for rplying. But my problem is how to get the cell position from QTableWidget::cellEntered(int, int) signal?

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to enable hot spotting in QTableWidget.

    You mean cordinates ?
    Have a look at QAbstractItemView::visualRect

  5. #5
    Join Date
    May 2009
    Posts
    31
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to enable hot spotting in QTableWidget.

    not the coordinates. By cell position i mean that ( row, column) position of cell.

  6. #6
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: how to enable hot spotting in QTableWidget.

    hmm isn't arguments passed by cellEntered(int, int) the row and column of the entered cell?
    Last edited by faldzip; 26th May 2009 at 12:16. Reason: I didn't read docs carefully :(
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  7. #7
    Join Date
    May 2009
    Posts
    31
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to enable hot spotting in QTableWidget.

    I think you didnt get my problem. Let me elaborate more:

    QTableWidget has one signal cellEntered(int row, int col). This signal is emitted when the mouse cursor enters a cell. The cell is specified by row and column, that qt itself finds out. But it doesn't return that row-col value to user.

    So my problem is when "cellEntered(int,int) signal is emitted i need to find the cell's row-col position so that i can attach appropriate tooltip with that.

  8. #8
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to enable hot spotting in QTableWidget.

    How are you connecting the signal to your slot ??
    From the slot you can use the row/column...
    Say you have connected -
    Qt Code:
    1. connect(m_tableWidget,SIGNAL(cellEntered(int,int)),this,SLOT(handleCellEntered(int,int)) );
    2. // Then in
    3. MyClass::handleCellEntered(int aRow,int aCol)
    4. {
    5. // aRow is row
    6. // aCol is column
    7. }
    To copy to clipboard, switch view to plain text mode 

  9. #9
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: how to enable hot spotting in QTableWidget.

    first of aamer4yu is right. you have the row and column from the signal (so you have it in your slot - or you can have it).
    Other thing is that, why can't you set the toolTip in the same place where the other item data is set?
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  10. #10
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: how to enable hot spotting in QTableWidget.

    Isn't it the thing you want?:
    Attached Images Attached Images
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

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

    Default Re: how to enable hot spotting in QTableWidget.

    Quote Originally Posted by AviMittal View Post
    I think you didnt get my problem. Let me elaborate more:

    QTableWidget has one signal cellEntered(int row, int col). This signal is emitted when the mouse cursor enters a cell. The cell is specified by row and column, that qt itself finds out. But it doesn't return that row-col value to user.

    So my problem is when "cellEntered(int,int) signal is emitted i need to find the cell's row-col position so that i can attach appropriate tooltip with that.
    The proper way of doing it is to either set the tooltip per index (aka cell) as I showed you in the very beginning of the thread or reimplement viewportEvent(), intercept QEvent::ToolTip there and show a proper tooltip based on QAbstractItemView::indexAt(). There is also a third way that involves subclassing the model and reimplementing QAbstractItemModel::data() for Qt::ToolTipRole but this requires that you use QTableView instead of QTableWidget.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #12
    Join Date
    May 2009
    Posts
    31
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to enable hot spotting in QTableWidget.

    Quote Originally Posted by faldżip View Post
    Isn't it the thing you want?:
    Ya.....how to do this ?

  13. #13
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: how to enable hot spotting in QTableWidget.

    I used QTableWidgetItem::setToolTip() :]
    Qt Code:
    1. ui->tableWidget->setRowCount(25);
    2. ui->tableWidget->setColumnCount(10);
    3. for (int row = 0; row < 25; ++row)
    4. {
    5. for (int col = 0; col < 10; ++col)
    6. {
    7. QTableWidgetItem *item = new QTableWidgetItem(tr("Item (%1, %2)").arg(row).arg(col));
    8. item->setToolTip(tr("ToolTip row = %1, col = %2").arg(row).arg(col));
    9. ui->tableWidget->setItem(row, col, item);
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

    Somewhere in your code you are setting some text to item and maybe other things like icon. In that place you can also set the appropriate tool tip like in my code: I create item with some text (passed to the constructor) and then I set tool tip and then I add the item to the TableWidget.
    Last edited by faldzip; 27th May 2009 at 08:02.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

Similar Threads

  1. Drag and Drop QTableWidget in UI file.
    By tpf80 in forum Qt Programming
    Replies: 3
    Last Post: 20th January 2009, 23:02
  2. QComboBox in QTableWidget : display troubles.
    By Nyphel in forum Qt Programming
    Replies: 2
    Last Post: 13th October 2007, 23:29
  3. QTableWidget issues
    By Djony in forum Qt Programming
    Replies: 42
    Last Post: 19th December 2006, 23:27
  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
  •  
Qt is a trademark of The Qt Company.