PDA

View Full Version : [QT3+XP] transparency and mouse tracking



incapacitant
17th February 2006, 17:38
hi

The following code has (at least) 2 problems :


// set background and size it correctly
QWidget *main = new QWidget( this );
( this )->resize( 569, 458 );
setPaletteBackgroundPixmap
( QPixmap::fromMimeSource( "images/Exemple_Background.png" ) );

// track mouse moves
setMouseTracking ( true );

// exit push button
QPushButton * pbClose = new QPushButton ( this );
pbClose->resize( QSize( 10, 10 ) );
pbClose->move( 551, 5 ); // position over background
pbClose->setMask( QBitmap() ); // for transparency

connect( pbClose, SIGNAL( clicked() ), this, SLOT( close() ) );
connect( pbClose, SIGNAL( QEvent::Enter ), this, SLOT ( changeCursor() ) );
connect( pbClose, SIGNAL( QEvent::Leave ), this, SLOT ( resetCursor() ) );

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 ?

high_flyer
17th February 2006, 18:59
Try:


// set background and size it correctly
QWidget *main = new QWidget( this );
( this )->resize( 569, 458 );
setPaletteBackgroundPixmap
( QPixmap::fromMimeSource( "images/Exemple_Background.png" ) );


// exit push button
QPushButton * pbClose = new QPushButton ( this );
// track mouse moves
pbClose->setMouseTracking ( true );

pbClose->resize( QSize( 10, 10 ) );
pbClose->move( 551, 5 ); // position over background
pbClose->setMask( QBitmap() ); // for transparency

connect( pbClose, SIGNAL( clicked() ), this, SLOT( close() ) );
connect( pbClose, SIGNAL( QEvent::Enter ), this, SLOT ( changeCursor() ) );
connect( pbClose, SIGNAL( QEvent::Leave ), this, SLOT ( resetCursor() ) );



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.

incapacitant
17th February 2006, 19:04
putting


pbClose->setMouseTracking ( true ); // does start the slots !



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.

high_flyer
17th February 2006, 19:08
putting


pbClose->setMouseTracking ( true ); // does start the slots !



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?

incapacitant
17th February 2006, 19:17
well, no these are the only slots.
and with

pbClose->setMask( QBitmap() );
it is 100% invisible (as I would like it)

high_flyer
17th February 2006, 19:22
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.

jacek
17th February 2006, 19:32
connect( pbClose, SIGNAL( QEvent::Enter ), this, SLOT ( changeCursor() ) );
connect( pbClose, SIGNAL( QEvent::Leave ), this, SLOT ( resetCursor() ) );
That's not the way to receive events. You must reimplement QWidget::enterEvent() and QWidget::leaveEvent () methods or use event filter.

high_flyer
17th February 2006, 19:36
OFCOURSE!!
Bahh... these are events... :rolleyes:
I think I need to do something elese for few minites... :-)

incapacitant
17th February 2006, 19:42
complete code :


#include <qpixmap.h>
#include <qpushbutton.h>
#include <qbitmap.h>
#include <qcursor.h>
#include <qevent.h>

#include "application.h"

ApplicationWindow::ApplicationWindow()
: QMainWindow( 0, "Application",
Qt::WStyle_Customize |
Qt::WStyle_Splash |
WDestructiveClose |
WGroupLeader )
{
// set background and size it correctly
QWidget *main = new QWidget( this );
( this )->resize( 569, 458 );
setPaletteBackgroundPixmap
( QPixmap::fromMimeSource( "images/Exemple_Background.png" ) );

// exit push button
QPushButton * pbClose = new QPushButton ( this );
// track mouse moves
pbClose->setMouseTracking ( true );

pbClose->resize( QSize( 10, 10 ) );
pbClose->move( 551, 5 ); // position over background
// pbClose->setMask( QBitmap() ); // for transparency

connect( pbClose, SIGNAL( clicked() ), this, SLOT( close() ) );
connect( pbClose, SIGNAL( QEvent::Enter ), this, SLOT ( changeCursor() ) );
connect( pbClose, SIGNAL( QEvent::Leave ), this, SLOT ( resetCursor() ) );
}


//************************************************** **************
ApplicationWindow::~ApplicationWindow()
{
}

//************************************************** **************
void ApplicationWindow::changeCursor()
{
close();
// QCursor( 2 ); //QCursor::PointingHandCursor);
return;
}

//************************************************** **************
void ApplicationWindow::resetCursor()
{
close();
return;
}


and regarding invisible widgets, you are correct I will have to design them. How ?
I have no clue at this time.

Thanks anyway

incapacitant
17th February 2006, 19:49
oops, i had not seen jacek comments. i will try. tx