Results 1 to 2 of 2

Thread: Tab keeps hover style after a context menu is closed

  1. #1
    Join Date
    Sep 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Tab keeps hover style after a context menu is closed

    Hi,

    I have added a custom context menu to the QTabWidget. However, if a user moves mouse over one of the tabs, right-clicks to display the context menu, moves the mouse away and clicks on some other control, the menu disappears but the tab keeps its hover style.

    A simple example of the way I am adding the context menu is below:
    Qt Code:
    1. class ContextMenuTabWidget : public QTabWidget
    2. {
    3. Q_OBJECT
    4. public:
    5. ContextMenuTabWidget(QWidget * parent = 0);
    6. public slots:
    7. void showContextMenu(const QPoint& point);
    8. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. ContextMenuTabWidget::ContextMenuTabWidget(QWidget * parent) : QTabWidget(parent)
    2. {
    3. connect(this, SIGNAL(customContextMenuRequested(const QPoint&)),
    4. this, SLOT(showContextMenu(const QPoint&)));
    5. }
    6.  
    7. void ContextMenuTabWidget::showContextMenu(const QPoint& point)
    8. {
    9. QMenu menu;
    10. menu.addAction(tr("Menu Item"));
    11. menu.exec(mapToGlobal(point));
    12. }
    To copy to clipboard, switch view to plain text mode 

    How can I avoid the problem of the tab keeping its hover style?

    Thanks in advance!

  2. #2
    Join Date
    Sep 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Tab keeps hover style after a context menu is closed

    If anyone is interested, I have solved it by firing a HoverLeave event if mouse moved away from the tab.

    Something like:
    Qt Code:
    1. int hoverTab = tabBar()->tabAt(tabBar()->mapFromGlobal(QCursor::pos()));
    2. if (clickedTab != hoverTab) {
    3. QEvent e(QEvent::HoverLeave);
    4. QApplication::sendEvent(tabBar(), &e);
    5. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Context menu
    By dejvis in forum Newbie
    Replies: 2
    Last Post: 20th September 2009, 22:02
  2. Qwt and context menu
    By giusepped in forum Qwt
    Replies: 1
    Last Post: 9th December 2008, 08:55
  3. Context Menu
    By RY in forum Newbie
    Replies: 1
    Last Post: 10th September 2008, 07:59
  4. [Style Sheet] QMenu::item:hover bug
    By spud in forum Qt Programming
    Replies: 3
    Last Post: 11th May 2007, 14:11
  5. QScrollBar context menu
    By ChasW in forum Qt Programming
    Replies: 1
    Last Post: 29th January 2007, 06:45

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.