Results 1 to 1 of 1

Thread: QToolTip with an item of a QVBoxLayout

  1. #1
    Join Date
    Mar 2010
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QToolTip with an item of a QVBoxLayout

    Hello to all of you.
    In the process of porting an application from Qt3 to Qt4, I met a serious problem concerning the use of a QToolTip object associated to an item of a QVBoxLayout made of a QLineEdit widget and a QTreeWidget ( where I want to see a list of files ( extension, name & path ))
    I built a small piece of code extracted from the real application and aiming that point.
    What happens ? : the creation of the main window with a menubar, a toolbar & a status bar seems to be correct; the creation of the QVBoxLayout and the insertion of the 2 items ( QLineEdit & QTreeWidget ) too : I can use both of them ( entering text in QLineEdit, selecting ( by clicking or double-clicking an item in QTreeWidget )) and connection between signal & slots seems to work fine.
    But the QToolTip object attached to QTreeWidget doesn't give me what I expect : it appears only when the mouse pointer enters LineEdit area ( the first item of QTreeWidget is tooltip'ed ) or a little bellow ( the the second item is shown ). It seems to me that the QToolTip "migrates" from QTreeWidget to QVBoxLayout. By inserting debug code in the QEvent::ToolTip I wrote to intercept the QEvent, I can see the position of the pointer when event occurs : the coordinates are ALWAYS relative to the QVBoxLayout and NEVER to the QTreeWidget. Of course I cannot use these coordinates.
    I was unable to get the position of each QLayoutItem in the layout ( I always got the position of the outer layout ! ) or their size or their geometry ( same kind of result ! )
    So I think that something is wrong in the way I create either the layout or insert the items ( QLineEdit & QTreeWidget ) : some attributes or parameter missing or even the order in which these operations are performed ( or ... I dont know what ).

    Following is a part of the code I use to setup the objects :

    Qt Code:
    1. SearchList::SearchList(int nSearchCol, QWidget* pParent, const char* szName) :
    2. QWidget(pParent),
    3. m_nSearchCol(nSearchCol)
    4. {
    5. Q_UNUSED(szName);
    6.  
    7. // Create the child widgets
    8. QVBoxLayout *pLayout = new QVBoxLayout;
    9. m_pEdit = new SearchLineEdit();
    10. m_pList = new QTreeWidget();
    11. // Set up the tooltip generator
    12. m_pList->setToolTip(QString());
    13. m_pToolTip = QString();
    14. pLayout->addWidget(m_pEdit);
    15. pLayout->addWidget(m_pList);
    16. setLayout(pLayout);
    To copy to clipboard, switch view to plain text mode 

    to build the QTreeWidget
    Qt Code:
    1. FileList::FileList(QWidget* pParent, const char* szName) :
    2. SearchList(1, pParent, szName),
    3. m_sRoot("/")
    4. {
    5. QSize headerItemSize;
    6. QHeaderView *pHeaderView;
    7. // Set the list's columns
    8. QTreeWidgetItem *headerItem = new QTreeWidgetItem();
    9.  
    10. headerItem->setText(0, "");
    11. headerItem->setText(1, "File");
    12. headerItem->setText(2, "Path");
    13. m_pList->setHeaderItem(headerItem);
    14. m_pList->setAllColumnsShowFocus(true);
    15. m_pList->setRootIsDecorated(false);
    16. m_pList->setAlternatingRowColors(true);
    17. m_pList->setMouseTracking(true);
    18. m_pList->setColumnCount(3);
    19. pHeaderView = m_pList->header();
    20. headerItemSize = pHeaderView->size();
    21. }
    To copy to clipboard, switch view to plain text mode 
    to handle QEvent::ToolYip event

    Qt Code:
    1. bool SearchList::event(QEvent *e)
    2. {
    3. if (e->type() == QEvent::ToolTip) {
    4. QHelpEvent *hEvent = static_cast<QHelpEvent *>(e);
    5. QPoint pt = hEvent->pos();
    6. QPoint globalPt = hEvent->globalPos();
    7.  
    8. fprintf(stderr, "SearchList::event: pos: X: %d Y: %d globalPos: X: %d Y: %d\n", pt.x(), pt.y(), globalPt.x(), globalPt.y());
    9.  
    10. // QTreeWidgetItem* pItem = m_pList->itemAt(pt - QPoint(0, 60));
    11. QTreeWidgetItem* pItem = m_pList->itemAt(pt);
    12. if ( pItem ) {
    13. QString sTip;
    14. getTip(pItem, sTip);
    15. QToolTip::showText(hEvent->globalPos(), sTip);
    16. } else {
    17. QToolTip::hideText();
    18. e->ignore();
    19. }
    20. return true;
    21. }
    22. return QWidget::event(e);
    23. }
    To copy to clipboard, switch view to plain text mode 

    If I change
    Qt Code:
    1. QTreeWidgetItem* pItem = m_pList->itemAt(pt);
    To copy to clipboard, switch view to plain text mode 
    into
    Qt Code:
    1. QTreeWidgetItem* pItem = m_pList->itemAt(pt - QPoint(0,60));
    To copy to clipboard, switch view to plain text mode 
    the behaviour is as expected. The "60" value is approximatly the height of QLineEdit + the height of QTreeWidget header. So it's obviously a matter of relative position of the pointer to the wrong object.

    Here are the classes I use ( only the first line of each of them )

    Qt Code:
    1. class SearchLineEdit : public QLineEdit
    2. {
    3. Q_OBJECT
    4. public:
    5. SearchLineEdit(QWidget* pParent = 0) : QLineEdit(pParent) {};
    6.  
    7. class SearchList : public QWidget
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. SearchList(int nSearchCol, QWidget* pParent = 0, const char* szName = 0);
    13.  
    14. class FileList : public SearchList, public FileListTarget
    15. {
    16. Q_OBJECT
    17.  
    18. public:
    19. FileList(QWidget* pParent = 0, const char* szName = 0);
    20. ~FileList();
    To copy to clipboard, switch view to plain text mode 

    Of course I can send the whole code if needed.
    Any help on that point, any suggestion, will very much appreciated.
    And above all, many thanks for reading that post and for any answer.
    Last edited by gilou; 28th March 2010 at 19:00.

Similar Threads

  1. Is the QToolTip::showText Bug?
    By cspp in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2009, 06:12
  2. problem in QTooltip
    By wagmare in forum Qt Programming
    Replies: 8
    Last Post: 6th April 2009, 14:09
  3. QToolTip width
    By Vladimir in forum Qt Programming
    Replies: 7
    Last Post: 3rd March 2007, 08:15
  4. QToolTip
    By suresh in forum Newbie
    Replies: 7
    Last Post: 6th September 2006, 15:00
  5. [QT3] QToolTip with Images (QPixMap) ?
    By BrainB0ne in forum Qt Programming
    Replies: 4
    Last Post: 27th January 2006, 08:31

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.