Results 1 to 10 of 10

Thread: [QT3+XP] transparency and mouse tracking

  1. #1
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    Question [QT3+XP] transparency and mouse tracking

    hi

    The following code has (at least) 2 problems :
    Qt Code:
    1. // set background and size it correctly
    2. QWidget *main = new QWidget( this );
    3. ( this )->resize( 569, 458 );
    4. setPaletteBackgroundPixmap
    5. ( QPixmap::fromMimeSource( "images/Exemple_Background.png" ) );
    6.  
    7. // track mouse moves
    8. setMouseTracking ( true );
    9.  
    10. // exit push button
    11. QPushButton * pbClose = new QPushButton ( this );
    12. pbClose->resize( QSize( 10, 10 ) );
    13. pbClose->move( 551, 5 ); // position over background
    14. pbClose->setMask( QBitmap() ); // for transparency
    15.  
    16. connect( pbClose, SIGNAL( clicked() ), this, SLOT( close() ) );
    17. connect( pbClose, SIGNAL( QEvent::Enter ), this, SLOT ( changeCursor() ) );
    18. connect( pbClose, SIGNAL( QEvent::Leave ), this, SLOT ( resetCursor() ) );
    To copy to clipboard, switch view to plain text mode 
    1. setMouseTracking must be wrongly implemented because it never starts the slots,
    2. if i include the line "pbClose->setMask( QBitmap() );" then the control is transparent,
    but it never signals the click. (w/o this line I can click but the background in not
    visible anymore.

    I tried various things but none worked, can you help me ?

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: [QT3+XP] transparency and mouse tracking

    Try:
    Qt Code:
    1. // set background and size it correctly
    2. QWidget *main = new QWidget( this );
    3. ( this )->resize( 569, 458 );
    4. setPaletteBackgroundPixmap
    5. ( QPixmap::fromMimeSource( "images/Exemple_Background.png" ) );
    6.  
    7.  
    8. // exit push button
    9. QPushButton * pbClose = new QPushButton ( this );
    10. // track mouse moves
    11. pbClose->setMouseTracking ( true );
    12.  
    13. pbClose->resize( QSize( 10, 10 ) );
    14. pbClose->move( 551, 5 ); // position over background
    15. pbClose->setMask( QBitmap() ); // for transparency
    16.  
    17. connect( pbClose, SIGNAL( clicked() ), this, SLOT( close() ) );
    18. connect( pbClose, SIGNAL( QEvent::Enter ), this, SLOT ( changeCursor() ) );
    19. connect( pbClose, SIGNAL( QEvent::Leave ), this, SLOT ( resetCursor() ) );
    To copy to clipboard, switch view to plain text mode 
    2. if i include the line "pbClose->setMask( QBitmap() );" then the control is transparent,
    but it never signals the click. (w/o this line I can click but the background in not
    visible anymore.
    If you set parts of the widget to be invisible with setMask(), the invisible parts will not react to mouse clicks, only the visible parts.

  3. #3
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: [QT3+XP] transparency and mouse tracking

    putting
    Qt Code:
    1. pbClose->setMouseTracking ( true ); // does start the slots !
    To copy to clipboard, switch view to plain text mode 


    even when displaying the button.

    And anyway how can you have a transparent button that will be possible to click ?
    I have not found another way.

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: [QT3+XP] transparency and mouse tracking

    Quote Originally Posted by incapacitant
    putting
    Qt Code:
    1. pbClose->setMouseTracking ( true ); // does start the slots !
    To copy to clipboard, switch view to plain text mode 


    even when displaying the button.
    Do you have any more signal/slots connection to pbClose beside the ones you show here?

    And anyway how can you have a transparent button that will be possible to click ?
    I have not found another way.
    Is it tottaly transparent, or only opaque to some degree?

  5. #5
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: [QT3+XP] transparency and mouse tracking

    well, no these are the only slots.
    and with
    Qt Code:
    1. pbClose->setMask( QBitmap() );
    To copy to clipboard, switch view to plain text mode 
    it is 100% invisible (as I would like it)

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: [QT3+XP] transparency and mouse tracking

    I can't explain why the slots fire on paintEvent.
    On the code you provided so far, I can't see an explanation to that behaviour.

    But you can't have a "clickable" invisible widget "out of the box" AFAIK, and it is logical to be so, since it makes no sense to have clickable yet invisible controls.
    You will have to implement your own style probobly to deal with 100% invisible clickable widgets.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [QT3+XP] transparency and mouse tracking

    Qt Code:
    1. connect( pbClose, SIGNAL( QEvent::Enter ), this, SLOT ( changeCursor() ) );
    2. connect( pbClose, SIGNAL( QEvent::Leave ), this, SLOT ( resetCursor() ) );
    To copy to clipboard, switch view to plain text mode 
    That's not the way to receive events. You must reimplement QWidget::enterEvent() and QWidget::leaveEvent () methods or use event filter.

  8. #8
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: [QT3+XP] transparency and mouse tracking

    OFCOURSE!!
    Bahh... these are events...
    I think I need to do something elese for few minites... :-)

  9. #9
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    Talking Re: [QT3+XP] transparency and mouse tracking

    complete code :
    Qt Code:
    1. #include <qpixmap.h>
    2. #include <qpushbutton.h>
    3. #include <qbitmap.h>
    4. #include <qcursor.h>
    5. #include <qevent.h>
    6.  
    7. #include "application.h"
    8.  
    9. ApplicationWindow::ApplicationWindow()
    10. : QMainWindow( 0, "Application",
    11. Qt::WStyle_Customize |
    12. Qt::WStyle_Splash |
    13. WDestructiveClose |
    14. WGroupLeader )
    15. {
    16. // set background and size it correctly
    17. QWidget *main = new QWidget( this );
    18. ( this )->resize( 569, 458 );
    19. setPaletteBackgroundPixmap
    20. ( QPixmap::fromMimeSource( "images/Exemple_Background.png" ) );
    21.  
    22. // exit push button
    23. QPushButton * pbClose = new QPushButton ( this );
    24. // track mouse moves
    25. pbClose->setMouseTracking ( true );
    26.  
    27. pbClose->resize( QSize( 10, 10 ) );
    28. pbClose->move( 551, 5 ); // position over background
    29. // pbClose->setMask( QBitmap() ); // for transparency
    30.  
    31. connect( pbClose, SIGNAL( clicked() ), this, SLOT( close() ) );
    32. connect( pbClose, SIGNAL( QEvent::Enter ), this, SLOT ( changeCursor() ) );
    33. connect( pbClose, SIGNAL( QEvent::Leave ), this, SLOT ( resetCursor() ) );
    34. }
    35.  
    36.  
    37. //****************************************************************
    38. ApplicationWindow::~ApplicationWindow()
    39. {
    40. }
    41.  
    42. //****************************************************************
    43. void ApplicationWindow::changeCursor()
    44. {
    45. close();
    46. // QCursor( 2 ); //QCursor::PointingHandCursor);
    47. return;
    48. }
    49.  
    50. //****************************************************************
    51. void ApplicationWindow::resetCursor()
    52. {
    53. close();
    54. return;
    55. }
    To copy to clipboard, switch view to plain text mode 
    and regarding invisible widgets, you are correct I will have to design them. How ?
    I have no clue at this time.

    Thanks anyway

  10. #10
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: [QT3+XP] transparency and mouse tracking

    oops, i had not seen jacek comments. i will try. tx

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.