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();
...
...
PIRButton->animateClick();
PIRWindow = new pir1();
PIRWindow->show();
PIRWindow->raise();
PIRWindow->activateWindow();
...
To copy to clipboard, switch view to plain text mode
In mainwindow.h:
...
private:
pir1 *PIRWindow;
...
...
private:
pir1 *PIRWindow;
...
To copy to clipboard, switch view to plain text mode
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:
...
{
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
);
}
}
...
...
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);
}
}
...
To copy to clipboard, switch view to plain text mode
In pir1.h:
...
private:
...
...
private:
QPixmap *background;
...
To copy to clipboard, switch view to plain text mode
I don't know where I'm doing wrong.
Bookmarks