Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Background problem witch QMdiSubWindow and paintEvent

Background problem witch QMdiSubWindow and paintEvent

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 735 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SergioB
    wrote on last edited by
    #1

    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);
    

    }

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved