Background problem witch QMdiSubWindow and paintEvent



  • Hi,
    I'm programming a little application using QMainWindow and a sub class of QMdiSubWindow. I use a sub class to plot a grid in the background of mdi subwindows using paintEvent and QPainter.
    All work was do using the common way and documented, but when one mdi subwindow are moved over the other the background of the bottom windows is not updated.
    I was try to make a screen capture of the problem, but when pressed any button or change the application focus, the subwindows background is updated.
    In the bottom I add some fragments of used source code.
    If you know whats is the problem or have some idea, please, tellme.
    Thanks a lot!

    Sergio

    /***** QMainWindow constructor *****/
    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow){

    ui->setupUi(this);
    

    // Add two subwindow to test the problem
    this->ui->mdiArea->addSubWindow(new subWnd());
    this->ui->mdiArea->addSubWindow(new subWnd());
    }

    /***** subWnd class definition *****/

    class subWnd : public QMdiSubWindow
    {
    public:
    subWnd();
    protected:
    virtual void paintEvent(QPaintEvent * event);
    };

    /***** and class implementation *****/
    #include "subwnd.h"
    #include <QPainter>
    #include <QPaintEvent>

    subWnd::subWnd(){

    setAttribute(Qt::WA_DeleteOnClose);
    

    }

    int cordToGrid(int v)
    {
    int ret;
    ret = v / 5;
    ret = ret * 5;
    return ret;
    }
    void subWnd::paintEvent(QPaintEvent * event){

    QPen lapiz(Qt::black);
    QBrush relleno(Qt::white);
    QPainter painter(this);
    lapiz.setWidth(1);
    lapiz.setStyle(Qt::DashLine);
    relleno.setStyle(Qt::NoBrush);
    painter.setPen(lapiz);
    painter.setBrush(relleno);
    int xIni = cordToGrid(event->rect().x());
    int yIni = cordToGrid(event->rect().y());
    for(int x = xIni; x < event->rect().width();x += 5)
       for(int y = yIni; y < event->rect().height(); y += 5)
            painter.drawPoint(x, y);
    painter.end();
    QMdiSubWindow::paintEvent(event);
    

    }


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    AFAIK, the usual way is to create a custom widget with the custom painting you want and set it as internal widget of the QMdiSubWindow.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.