PDA

View Full Version : Second Window properties



felo188
2nd August 2011, 13:32
Hi.

I'm trying to set a second window (called pir1) size and fill a background. i don't have problem to set this in first window (MainWindow).
I created pir1.h, pir1.cpp and in MainWindow.cpp i have this (below code is in event filter):

...
PIRWindow = new pir1();
PIRWindow->show();
PIRWindow->raise();
PIRWindow->activateWindow();
...
I tried use a code that works with MainWindow so I created in pir1.cpp paint event with draw pixmap but it's didn't works.

tbscope
2nd August 2011, 16:35
but it's didn't works.
Please explain what it is that does not work in great details.
Otherwise a possible answer would be to adjust your Heisenberg Compensator to the correct compensation level.

felo188
3rd August 2011, 08:56
In my ui i have some buttons. When the button is clicked shows new window pir1 so showing new window is working. In MainWindow I set pixmap on background. I want to set background in the new window pir1 too.
In MainWindow.cpp i have some code that is in eventFilter:

...
PIRButton->animateClick();
PIRWindow = new pir1();
PIRWindow->show();
PIRWindow->raise();
PIRWindow->activateWindow();
...
In mainwindow.h:
...
private:
pir1 *PIRWindow;
...
I created new file pir1.cpp, pir1.h and pir1.ui just following in qt File->New File or Project->QT Designer Form Class.
The background in MainWindow is set in paintEvent where is declared what and how should be displayed. And it's working as I wanted.
In the pir1.cpp i try to display background in the same way so I declared paintEvent in the same way as in mainwindow class but it's don't working (the background isn't change to my pixmap).
In pir1.cpp:

...
void pir1::paintEvent(QPaintEvent *ev)
{
QPainter painter;
background = new QPixmap("path to file");//path is correct
QPixmap scaledPixMap = background->scaled(QSize(300,300));//I set window size in pir1.ui
if(!background->isNull())
{
painter.drawPixmap(QPoint(0,0),scaledPixMap);
}
}
...
In pir1.h:
...
private:
QPixmap *background;
...
I don't know where I'm doing wrong.

felo188
4th August 2011, 09:21
Enybody can help me? I don't know why I can add some buttons on second window pir1 but i'm not able to draw anythink.

Edit:
I found a solution :) The simplest thinks are the best.

...
QPainter painter(this);
...