Results 1 to 8 of 8

Thread: Painting within different Widgets and updating them individually

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2015
    Posts
    5
    Qt products
    Qt5
    Platforms
    Windows

    Question Painting within different Widgets and updating them individually

    Hello,

    I'm new to Qt and I'm working on a program where I need to paint on different Widgets. In the end, I would like to display these widgets frameless and use the main window to change the paintings in these widgets step by step (text, picture, basic drawings). I'm using Qt 5.5 under Windows.

    Currently my program consists of a main window with three buttons:
    1. Start -> creates five Widgets (class OutputWindow)
    2. Test -> paints within the main window
    3. Quit -> ends the program

    By clicking inside one of the five OutputWindow(s) (A, B, C, D and E), I can paint within each of these Widgets. Unfortunately, I can only paint within one Widget at a time. But I need to preserve the paintings in each Widget and change them individually. How can I preserve the current paintings while drawing on another Widget? (How should I handle update() / this situation?)

    The second problem is that I'm not able to trigger the paintEvent for the OutputWindow(s) from within the Main Window. How can I use (for example) a button from the Main Window (class ControlWindow) to call a paintEvent from another class (OutputWindow) to paint on a Widget derived from this class?

    I'm not sure if I've understod the use / reimplementation of paintEvent correctly

    To make my problem clear, I've attached some screenshots. And of course here is a part of the Code (you can find the whole project attached as a zip-file!):

    controllerWindow.cpp | set variable true if button "Test" (btnTest) was pushed
    Qt Code:
    1. void ControllerWindow::tempButtonPushed()
    2. {
    3. vtempButtonPushed = true;
    4. update();
    5. }
    To copy to clipboard, switch view to plain text mode 

    controllerWindow.cpp | paintEvent
    Qt Code:
    1. void ControllerWindow::paintEvent(QPaintEvent*)
    2. {
    3. if (vtempButtonPushed == true)
    4. {
    5. QPainter painter(this);
    6. QPen pen(Qt::red, 10, Qt::SolidLine, Qt::SquareCap, Qt::BevelJoin);
    7.  
    8. painter.setPen(pen);
    9. painter.drawLine(0, 0, 800, 800);
    10.  
    11. vtempButtonPushed = false;
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 

    outputWindow.cpp | set variable true if mouse button was clicked
    Qt Code:
    1. void OutputWindow::mousePressEvent(QMouseEvent*)
    2. {
    3. vtempButtonPushed = true;
    4. update();
    5. }
    To copy to clipboard, switch view to plain text mode 

    outputWindow.cpp | paintEvent
    Qt Code:
    1. void OutputWindow::paintEvent(QPaintEvent*)
    2. {
    3. if (vtempButtonPushed == true)
    4. {
    5. QPainter painter(this);
    6. QPen pen(Qt::blue, 10, Qt::SolidLine, Qt::SquareCap, Qt::BevelJoin);
    7.  
    8. painter.setPen(pen);
    9. painter.drawLine(0, 0, 800, 800);
    10.  
    11. vtempButtonPushed = false;
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 

    Thank you in advance!
    Max
    Attached Images Attached Images
    Attached Files Attached Files

Similar Threads

  1. Updating widgets
    By The 11th plague of Egypt in forum Qt Programming
    Replies: 17
    Last Post: 28th September 2011, 19:41
  2. Painting a WebPage to the FrameBuffer without Widgets
    By DaRabman in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 10th August 2011, 16:14
  3. Replies: 3
    Last Post: 29th August 2010, 16:18
  4. QDockWidget::title is painting over other widgets with QSS
    By edisongustavo in forum Qt Programming
    Replies: 0
    Last Post: 16th March 2010, 23:44
  5. Not updating while painting in QMdiArea
    By rippa in forum Qt Programming
    Replies: 18
    Last Post: 14th April 2008, 17:35

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.