December 28, 2011

pratik041 pratik041
Lab Rat
346 posts

How parent object affect painting to child object?

Page  
1

I am painting the child object using event filter. I am getting improper painting in child widget but If i am removing parent object then i am getting proper painting.

 Signature 

Pratik Agrawal

23 replies

December 28, 2011

Lukas Geyer Lukas Geyer
Lab Rat
2074 posts

Well, you might add some code that shows the problematic behaviour.

December 28, 2011

pratik041 pratik041
Lab Rat
346 posts

Lukas Geyer wrote:
Well, you might add some code that shows the problematic behaviour.

I am using this code for painting in child widget.
  1. bool ofi_vc_gui::eventFilter (QObject *obj, QEvent *event) {
  2.  
  3.     // Check for the paint event.
  4.     if (event->type () == QEvent::Paint) {
  5.         QPainter paint(window); // Create a paint object.
  6.  
  7.        QRect source = QRect(0, 0, dlg_data.cx, dlg_data.cy);
  8.  
  9.      
  10.         QRect target = QRect(0, 0, dlg_data.cx, dlg_data.cy);
  11.  
  12.         paint.drawPixmap (target, pixmap, source);
  13.  
  14.         return true;
  15.     } else {
  16.         return QObject::eventFilter (obj, event);
  17.     }
  18. }

In parent widget i am setting image by stylesheet.

 Signature 

Pratik Agrawal

December 28, 2011

Lukas Geyer Lukas Geyer
Lab Rat
2074 posts

And what does proper resp. improper painting mean for you? Can you provide a screenshot showing how it should look like and how it actually looks like?

December 28, 2011

Andre Andre
Robot Herder
6394 posts

Why do you use an eventfilter for painting? That seems wrong.

December 28, 2011

pratik041 pratik041
Lab Rat
346 posts
Lukas Geyer wrote:
And what does proper resp. improper painting mean for you? Can you provide a screenshot showing how it should look like and how it actually looks like?

ya for image see the link below
http://www.imgplace.com/viewimg221/4369/95paint.png
The white color around the qlineedit widget corresponding to emil-id and password is the problem.

 Signature 

Pratik Agrawal

December 28, 2011

pratik041 pratik041
Lab Rat
346 posts
Andre wrote:
Why do you use an eventfilter for painting? That seems wrong.

Actually i am making a general class inheriting from qobject. Inside that i have child window which i am painting. Can you please say me what is wrong in doing that?

 Signature 

Pratik Agrawal

December 28, 2011

Andre Andre
Robot Herder
6394 posts

Much. Widgets are supposed to paint themselves. You return true from your filter, which means that the widget cannot take responsibility for painting its contents or its borders or its children.

December 28, 2011

pratik041 pratik041
Lab Rat
346 posts
Andre wrote:
Much. Widgets are supposed to paint themselves. You return true from your filter, which means that the widget cannot take responsibility for painting its contents or its borders or its children.

so how can i solve this problem?

 Signature 

Pratik Agrawal

December 28, 2011

Andre Andre
Robot Herder
6394 posts

Just use the system as it was designed to be used: by letting each widget paint itself.

December 28, 2011

pratik041 pratik041
Lab Rat
346 posts

Andre wrote:
Just use the system as it was designed to be used: by letting each widget paint itself.

ok

 Signature 

Pratik Agrawal

December 29, 2011

pratik041 pratik041
Lab Rat
346 posts
Andre wrote:
Just use the system as it was designed to be used: by letting each widget paint itself.

I have tried as you told but i am getting the same problem but the problem is coming in mac only not in windows.But one thing i noticed that when we press tab key the paint event is called infinite number of times.

 Signature 

Pratik Agrawal

December 29, 2011

Andre Andre
Robot Herder
6394 posts

Sorry, my crystal ball is broken, so I cannot see your code without you posting it.

December 29, 2011

pratik041 pratik041
Lab Rat
346 posts

Andre wrote:
Sorry, my crystal ball is broken, so I cannot see your code without you posting it.

this is the code for paint event which i have used
  1. void ofi_vc_gui_panel::paintEvent (QPaintEvent *event)
  2. {
  3.     QPainter paint(this); // Create a paint object.
  4.  
  5.     // Store the source rect of the image.
  6.     QRect source = QRect(0, 0, dlg_data.cx, dlg_data.cy);
  7.  
  8.     // Store the target rect where image is to be drawn.
  9.     QRect target = QRect(0, 0, dlg_data.cx, dlg_data.cy);
  10.  
  11.     // Draw the image.
  12.     paint.drawPixmap (target, pixmap, source);
  13.  
  14.     i++;
  15.     qDebug ()<<"event"<<i;
  16. }

 Signature 

Pratik Agrawal

December 29, 2011

Andre Andre
Robot Herder
6394 posts

How about you start out with a call to QWidget::paintEvent(event); between your lines 2 and 3? Replace the QWidget with whatever is the base class of your widget. That way, the base class also gets a chance to do painting.

December 29, 2011

pratik041 pratik041
Lab Rat
346 posts
Andre wrote:
How about you start out with a call to QWidget::paintEvent(event); between your lines 2 and 3? Replace the QWidget with whatever is the base class of your widget. That way, the base class also gets a chance to do painting.

I have tried this also but same problem persists. Do you have mac system? If you have i will post you the sample code so that you can check.

 Signature 

Pratik Agrawal

Page  
1

  ‹‹ facing problem to arrange UI items.      [SOLVED] Complete but simple CMake example ››

You must log in to post a reply. Not a member yet? Register here!