Results 1 to 3 of 3

Thread: mouseMoveEvent show/hide

  1. #1
    Join Date
    Dec 2009
    Posts
    65
    Thanks
    10
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default mouseMoveEvent show/hide

    i have widget that should contain stretched QTextEdit and a overlay widget with some buttons, something like this
    Qt Code:
    1. ________________________
    2. | QTextEdit _____ |
    3. | | | |
    4. | |____| |
    5. | |
    6. | |
    7. | |
    8. | |
    9. |_______________________|
    To copy to clipboard, switch view to plain text mode 
    (hope that picture looks right)

    I have trouble implementing this simple behaviour:
    if mouse is in the rect where widget widget with buttons should be, show widget with buttons
    when the mouse leaves the rect, hide the widget
    anyone tried to achive something similar?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: mouseMoveEvent show/hide

    What have you actually tried?

    If you actually hide() the widget then it is not there to receive and process mouse events; so you you cannot use the mouse events of the widget itself to show() it. You could use the mouse events of the widget containing the disappearing widget to make it reappear.
    "We can't solve problems by using the same kind of thinking we used when we created them." -- Einstein
    If you are posting code then please use [code] [/code] tags around it - makes addressing the problem easier.

  3. #3
    Join Date
    Dec 2009
    Posts
    65
    Thanks
    10
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: mouseMoveEvent show/hide

    I thought it would be simple like this
    Qt Code:
    1. void MessageForm::mouseMoveEvent(QMouseEvent *mme)
    2. {
    3. if(mme->type() == QMouseEvent::MouseMove){
    4. if(ui->actions->rect().contains(mme->pos())){
    5. ui->actions->setVisible(true);
    6. }
    7. else{
    8. ui->actions->setVisible(false);
    9. }
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 
    i am not using mouse event of widget with buttons but from parent widget. The first problem was one overlay floating widget and one stretch widget. solved with
    Qt Code:
    1. void MessageForm::resizeEvent(QResizeEvent* re) {
    2. Q_UNUSED(re);
    3. ui->actions->move(width() - ui->actions->width() - 20, 20 );
    4. ui->textEdit->resize(this->size());
    5. }
    To copy to clipboard, switch view to plain text mode 

    in form constructor i have
    Qt Code:
    1. ui->setupUi(this);
    2. setMouseTracking(true);
    3. ui->textEdit->move(0,0);
    4. ui->actions->setVisible(false);
    5. resizeEvent(NULL);
    To copy to clipboard, switch view to plain text mode 

    but, of course, there is QTextEdit that takes mouse events. It doesnt feel right to reimplement QTextEdit (it is not realy text editing function what am i reimplementing), but it takes away mouse events i intended from form.
    So i thought that i just made a blunder, and that i am doing it wrong. Maybe someone here acomplished same thing.
    Or, Is there a way for parent widget tho know the mouse position if the mouse is over the widget itself and/or its children widgets?

Similar Threads

  1. Hide/Show problem
    By premroxx in forum Newbie
    Replies: 1
    Last Post: 9th September 2011, 15:33
  2. how to show and hide frames?
    By rambo83 in forum Qt Programming
    Replies: 2
    Last Post: 6th January 2010, 09:53
  3. Hide and Show QMenu
    By febil in forum Qt Programming
    Replies: 3
    Last Post: 25th March 2009, 09:31
  4. hide from taskbar but show to ALT-TAB
    By musikit in forum Qt Programming
    Replies: 0
    Last Post: 15th August 2008, 16:14
  5. Show or hide a form
    By Gayathri in forum Newbie
    Replies: 11
    Last Post: 17th November 2006, 12:39

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.