I checked the opacity value and it is valid because equal to 0.5.
Here are some more details about my application :
* it is an SDI application generated with the wizard
* I implement the init slot in which I set the palette background pixmap, I create a timer and connect its timeout signal to a custom slot, finally I create my custom widget and set its opacity to 0.5
* in the slot connected to the timer timeout signal I call the update method of my widget
Here is the specific code of my application :
void TransparentWidgetMainWindow::init()
{
// ...
setPaletteBackgroundPixmap
(QPixmap("E:\\pix.png"));
// ...
pWidget = new CMyWidget(this, "toto");
pWidget->setGeometry(10, 10, 140, 200);
pWidget
->setFocusPolicy
(QWidget::StrongFocus);
pWidget->setWindowOpacity(0.2);
// ...
connect(pTimer, SIGNAL(timeout()), this, SLOT(processTimerTimeout()));
pTimer->start(100);
}
void TransparentWidgetMainWindow::processTimerTimeout()
{
pWidget->update();
}
void TransparentWidgetMainWindow::init()
{
// ...
setPaletteBackgroundPixmap(QPixmap("E:\\pix.png"));
resize(QSize(800, 480));
// ...
pWidget = new CMyWidget(this, "toto");
pWidget->setGeometry(10, 10, 140, 200);
pWidget->setFocusPolicy(QWidget::StrongFocus);
pWidget->setWindowOpacity(0.2);
// ...
pTimer = new QTimer(this);
connect(pTimer, SIGNAL(timeout()), this, SLOT(processTimerTimeout()));
pTimer->start(100);
}
void TransparentWidgetMainWindow::processTimerTimeout()
{
pWidget->update();
}
To copy to clipboard, switch view to plain text mode
and here is the implementation code of my custom widget :
CMyWidget
::CMyWidget(QWidget* parent,
const char* name, WFlags f
):m_pPixmap(0)
{
// ...
if( !m_pPixmap )
}
CMyWidget::~CMyWidget()
{
if( m_pPixmap )
{
delete m_pPixmap;
m_pPixmap = 0;
}
}
{
p.drawPixmap(ev->rect().x(), ev->rect().y(), *m_pPixmap, ev->rect().x(), ev->rect().y(), 140, 200);
}
CMyWidget::CMyWidget(QWidget* parent, const char* name, WFlags f):
QWidget(parent, name, f),
m_pPixmap(0)
{
// ...
if( !m_pPixmap )
m_pPixmap = new QPixmap(QImage("E:\\\\anotherpix.png"));
}
CMyWidget::~CMyWidget()
{
if( m_pPixmap )
{
delete m_pPixmap;
m_pPixmap = 0;
}
}
void CMyWidget::paintEvent(QPaintEvent* ev)
{
QPainter p(this);
p.drawPixmap(ev->rect().x(), ev->rect().y(), *m_pPixmap, ev->rect().x(), ev->rect().y(), 140, 200);
}
To copy to clipboard, switch view to plain text mode
The aim of this widget is not (for the moment) to be well designed, it is to be functional ... but in fact it is not yet functional.
As proposed in a previous answer of this post, I tried to set specific flag values passed in my widget constructor in order to configure it as a main window could be (it was proposed because a call setWindowOpacity has an effect on a main window), but settings my widget as a top level widget (as is my main window) does not solve my problem ... in fact I notice that the paintEvent method of my widget is never called.
I hope thoose details could help.
Bookmarks