Hey,
i want to let it sow with qt. The idea was to move three snowflakes (pictures) over a qwidget. Have anybody a tip for my how can i do that or know example that can do that?
Hey,
i want to let it sow with qt. The idea was to move three snowflakes (pictures) over a qwidget. Have anybody a tip for my how can i do that or know example that can do that?
It depends what exactly you want to achieve. If you want to "snow" over an existing widget, you have to install an event filter, intercept its paint event, use QWidget::render() to render the widget to a pixmap, paint the pixmap on the widget and then paint your flakes. If you don't need to interact with this widget, you can simplify things by setting a child widget on the window that will cover the whole window below, make it transparent and paint flakes on it.
whitefurrows (28th November 2008)
Hi,
sorry my late answer, i don't have get a notification to your message. Now i have try to let it snow, but i cant paint a snowflake in my mainwindow. Can
anybody take a look to my attachment and help my please.
Thanks in advance
You need to do the painting inside a QWidget::paintEvent().
Call QWidget::update() when your timer fires (this in turn will trigger the repaint).
In paintEvent() paint the snowflakes according to your state (e.g. the time passed.)
HTH
whitefurrows (28th November 2008)
Hi,
i have try like this:
Qt Code:
connect(timer, SIGNAL(timeout()), this, SLOT(update())); timer->start(1000); { QPixmap picture; qDebug() << picture.load(":flake_01.png"); // load picture (qDebug() == true) QPainter painter; painter.begin(this); // paint in MainWindow painter.drawPixmap(150, 150, 100, 100, picture); // draw the picture at (150,150) painter.end(); // painting done }To copy to clipboard, switch view to plain text mode
but my picture was not paint. What is wrong?
a) for efficiency: do not load the image every time paint event gets called
b) add a drawLine and/or qDebug to make sure the function gets executed
whitefurrows (28th November 2008)
OK, i can do that.a) for efficiency: do not load the image every time paint event gets called
the function gets executed, but if i try this:b) add a drawLine and/or qDebug to make sure the function gets executed
Qt Code:
QPainter painter; painter.begin(this); painter.setPen(Qt::black); painter.end();To copy to clipboard, switch view to plain text mode
i cant see a result. Can you help me, please?
Theres something with QMainWindow...
convert QMainWindow to QWidget and try,,,
Qt Code:
{ QPixmap picture; bool ret = picture.load(":flake_01.png"); // load picture (qDebug() == true) painter.drawPixmap(110, 110, picture); // draw the picture at (150,150) }To copy to clipboard, switch view to plain text mode
i got it... though background is not covering whole area,,, but u can scale it anytime
or use..
painter.drawTiledPixmap(rect(),QPixmap(":backgroun d.png") ); instead of line 7
whitefurrows (28th November 2008)
I have convert my QMainWindow to QWidget and all work's fine, but now i can't use my QMenuBar:
Qt Code:
connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit()));To copy to clipboard, switch view to plain text mode
What can i do?
so u made a widget,, and its working... good..
next step is to set this widget as central widget of QMainWindow![]()
whitefurrows (28th November 2008)
Thank you for your help, now it's all OK.
But notice you must setAutoFillBackground(true) to display the backgound from the widget.
Bookmarks