Results 1 to 3 of 3

Thread: Mouse events with StackAll QStackedLayout

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Join Date
    Apr 2010
    Location
    Russian Federation, Kaluga
    Posts
    20
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Mouse events with StackAll QStackedLayout

    see answer of Thierry Bastian for https://bugreports.qt.nokia.com/browse/QTBUG-3868
    Only the current page is active. The button on the other page just appears there because your current page is not opaque. That doesn't mean that it is transparent to mouse events.
    So you can capture mouse events at mainWidget and send it to needed control (according with mouse position) - but this way assume that you have pointer to all needed control at all stack. The following code show example:
    Qt Code:
    1. #include <QtGui>
    2. class CMainWidget : public QWidget
    3. {
    4. QPushButton*m_video_but;
    5. public:
    6. CMainWidget(QWidget*parent=0):QWidget(parent)
    7. {
    8. setMouseTracking(true);
    9. QStackedLayout*stack = new QStackedLayout(this);
    10. stack->setStackingMode(QStackedLayout::StackAll);
    11. QWidget*video_widget = new QWidget;
    12. QVBoxLayout*v_layout = new QVBoxLayout(video_widget);
    13. m_video_but = new QPushButton("Video");
    14. v_layout->addWidget(m_video_but);
    15. v_layout->addStretch();
    16. stack->addWidget(video_widget);
    17. QWidget*control_widget = new QWidget;
    18. v_layout = new QVBoxLayout(control_widget);
    19. v_layout->addStretch();
    20. v_layout->addWidget(new QPushButton("Controls"));
    21. stack->addWidget(control_widget);
    22. stack->setCurrentWidget(m_control_widget);
    23. }
    24. private:
    25. void mouseEvent(QMouseEvent*ev)
    26. {
    27. if(m_video_but->rect().contains(ev->pos()))
    28. qApp->sendEvent(m_video_but,ev);
    29. }
    30. void mousePressEvent(QMouseEvent*ev) { mouseEvent(ev); }
    31. void mouseReleaseEvent(QMouseEvent*ev) { mouseEvent(ev); }
    32. void mouseDoubleClickEvent(QMouseEvent*ev) { mouseEvent(ev); }
    33. };
    34.  
    35. int main(int argc, char *argv[])
    36. {
    37. QApplication a(argc, argv);
    38. CMainWidget w;
    39. w.show();
    40. return a.exec();
    41. }
    To copy to clipboard, switch view to plain text mode 

    The other way not use stack layout the following code illustrate it:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5. QApplication a(argc, argv);
    6.  
    7. QWidget mainWidget;
    8. mainWidget.setFixedSize(150,80);
    9.  
    10. QHBoxLayout*h_layout = new QHBoxLayout(&mainWidget);
    11. h_layout->setMargin(10);
    12. h_layout->setSpacing(10);
    13.  
    14. QPushButton*but_left = new QPushButton("LEFT");
    15. but_left->setFixedSize(60,60);
    16. QPushButton*but_right = new QPushButton("RIGHT");
    17. but_right->setFixedSize(but_left->size());
    18. mainWidget.layout()->addWidget(but_left);
    19. mainWidget.layout()->addWidget(but_right);
    20.  
    21. //NOTE: important that widget, which isn't in layout was a child of main widget
    22. // also overlay shall be added to mainWidget child's list after it's layout
    23. QPushButton*but_overlay = new QPushButton("overlay",&mainWidget);
    24. but_overlay->setFixedSize(40,20);
    25. QFont font;
    26. font.setPixelSize(6);
    27. but_overlay->setFont(font);
    28. but_overlay->move(55,30); //at center of main widget;
    29.  
    30. mainWidget.show();
    31. return a.exec();
    32. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by grin; 14th November 2011 at 23:24.

  2. The following user says thank you to grin for this useful post:

    Oleg (15th November 2011)

Similar Threads

  1. Replies: 3
    Last Post: 8th October 2011, 09:46
  2. Replies: 6
    Last Post: 9th September 2008, 20:43
  3. Mouse Events
    By daviddoria in forum Qt Programming
    Replies: 6
    Last Post: 13th May 2008, 11:55
  4. mouse events
    By xyzt in forum Newbie
    Replies: 3
    Last Post: 23rd March 2008, 11:14
  5. mouse moving don't produce mouse events
    By coralbird in forum Qt Programming
    Replies: 1
    Last Post: 13th September 2006, 06:13

Tags for this Thread

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.