Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to can i stop from painting the background widget in paintevent?



  • Hello,

    I am using Qt 5.12.3, and visual studio 2017.

    I am plotting the graph in real time in my application. I repainting the canvas of graph whenever the data point is arrived.

    On paint event the canvas is repaint with background widget also.

    How to can I stop from painting the background widget in paintevent?

    I would like to just add the data point on plot.

    I can set the cliping area at particular location. but if any other widget is available in backside of clipping rect then it is showing?

    On paint event i am getting plot like below pic.
    76d6173c-c8cd-478c-92b5-b4d4388c138e-image.png

    I would like something like below pic even another Qwidget is still on background.
    e62b8fe6-cd83-4838-8d9f-604b2639d659-image.png

    Any suggestion?


  • Lifetime Qt Champion

    @Yash001
    Well you could just keep a map of open windows, so you dont have to loop all windows but
    if i understand you correctly, it gets heavy as the other open windows are still active ?

    You could an install event filer on them to eat all event they get, ( include paintEvent) but
    is it not so nice as it will look odd if you dont hide it.

    You could try to use QWidget::stackUnder()
    to hide it under the other one but it would still be active.

    So not sure
    if you dont want to hide it
    and it should still be active to get events etc.
    what you want it to do ?
    simply paint nothing if told so but still be a window and do what else it does ?


  • Lifetime Qt Champion

    Hi
    You mean to make the front widget completely transparent so it draws its data point as overlay on the widget under it or what do you mean ?



  • @mrjj
    If I understand correctly then yes.

    In general I do have graph like below pic whenever data is not arrived.

    30d89473-029b-40ec-9269-8e87d3921c04-image.png

    Curve (blue line in my first pic) will plot on graph whenever the live data is arrived. I am using paint event to make visible data point on graph.

    This are the flag set in canvas on graph.
    setAttribute(Qt::WA_PaintOnScreen, true);
    setAttribute(Qt::WA_NoSystemBackground, true);


  • Lifetime Qt Champion

    Hi
    But why you want to have 2 widgets then ?
    Could you not just draw 2 graphs on the first widget ?

    it looks like when you get data, you create yet another QWT widget ?



  • @mrjj said in How to can i stop from painting the background widget in paintevent?:

    it looks like when you get data, you create yet another QWT widget ?

    Yes, I do have different exp. every time QWT widget create while starting of new experiment.

    lets say I have exp A and exp B.

    if user will start expA then subwindowA will create with button and Qwtplot.
    if user will start expB then subwindowB will create with button and Qwtplot.

    Now if live data arrived and if data point is for expA then it is visible in Qwtplot of subwindowA .
    if data point is for expB then it is visible in Qwtplot of subwindowB .

    Now if I will click on restore down button 3fd8b7be-a85f-4803-b061-e4017c51be03-image.png of subwindowA and put in back side of canvas of Qwtplot in subwindowB. ( currently subwindowB is in Maximized stat)

    then subwindowA widget is showing in canvas of Qwtplot in subwindowB while data point of arrive of expB.


  • Lifetime Qt Champion

    @Yash001
    Ok so you do want 2 widgets.
    But one thing i wonder if you zoom the A one, then when you draw the B one as overlay it would be in wrong positions. But you dont plan to zoom ?

    In any case, im not sure you can tell QWT to not draw the background grid.
    You can remove all borders etc but I think to might need to subclass the QWT class and fiddle with
    its paintEvent function to get it to not draw the grid etc.

    Maybe its enough to make a custom
    https://qwt.sourceforge.io/class_qwt_plot_grid.html#details
    and have it draw noting.



  • @mrjj said in How to can i stop from painting the background widget in paintevent?:

    But one thing i wonder if you zoom the A one, then when you draw the B one as overlay it would be in wrong positions. But you don't plan to zoom ?

    User will interact one Qwtplot widget at time. it is already handle in my code. it work perfectly.

    In any case, im not sure you can tell QWT to not draw the background grid.
    You can remove all borders etc but I think to might need to subclass the QWT class and fiddle with
    its paintEvent function to get it to not draw the grid etc.

    I don't want to hide the grid.
    I think we are not on same page. Let me give you more detail with pic.

    Here the user start expA.
    At that time window is created. The title of window Plus1102[ch 1] expA .....
    b17c6f1f-9f45-4564-9ea9-b9c552229515-image.png

    Now expA is stop and click on restore down button, and place window Plus1102[ch 1] expA on right side.

    88ddc12d-e02a-44e9-a818-c39c126730f5-image.png

    now start expB and At that time another window is created. The title of window Plus1102[ch 1] expB .....

    b1ece283-fcc7-4bfd-836b-f4685da27aaf-image.png

    Now you can see Plus1102[ch 1] expA is showing in canvas of ``Plus1102[ch 1] expB ....```.

    I want to completely hide the window Plus1102[ch 1] expA from canvas of ``Plus1102[ch 1] expB ....```.


  • Lifetime Qt Champion

    @Yash001
    Ok, I think i understand now but
    then i get confused why you simply dont call hide() on the window you want to hide?



  • @mrjj
    I try that thing. But It is make slow speed in creation of window as per number of windows is increasing, Because I need to iterate all the windows for hide.

    Sometime many experiment run at time, and received events in background.
    There are few other requirements also so that I am not hiding window.


  • Lifetime Qt Champion

    @Yash001
    Well you could just keep a map of open windows, so you dont have to loop all windows but
    if i understand you correctly, it gets heavy as the other open windows are still active ?

    You could an install event filer on them to eat all event they get, ( include paintEvent) but
    is it not so nice as it will look odd if you dont hide it.

    You could try to use QWidget::stackUnder()
    to hide it under the other one but it would still be active.

    So not sure
    if you dont want to hide it
    and it should still be active to get events etc.
    what you want it to do ?
    simply paint nothing if told so but still be a window and do what else it does ?



  • @mrjj
    Thank you sir for helping me and direction. I am able to solve this issue by

    1. setting the clipping area properly on graph.
    2. Use QWidget::update() instead of QWidget::repaint().