How parent object affect painting to child object?
-
[quote author="Lukas Geyer" date="1325070691"]Well, you might add some code that shows the problematic behaviour.[/quote]
I am using this code for painting in child widget.
@bool ofi_vc_gui::eventFilter (QObject *obj, QEvent *event) {// Check for the paint event. if (event->type () == QEvent::Paint) { QPainter paint(window); // Create a paint object. QRect source = QRect(0, 0, dlg_data.cx, dlg_data.cy); QRect target = QRect(0, 0, dlg_data.cx, dlg_data.cy); paint.drawPixmap (target, pixmap, source); return true; } else { return QObject::eventFilter (obj, event); }
}@
In parent widget i am setting image by stylesheet. -
[quote author="Lukas Geyer" date="1325071844"]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?[/quote]
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. -
[quote author="Andre" date="1325071995"]Why do you use an eventfilter for painting? That seems wrong.[/quote]
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?
-
[quote author="Andre" date="1325072688"]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. [/quote]
so how can i solve this problem?
-
[quote author="Andre" date="1325073247"]Just use the system as it was designed to be used: by letting each widget paint itself. [/quote]
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.
-
[quote author="Andre" date="1325147762"]Sorry, my crystal ball is broken, so I cannot see your code without you posting it.[/quote]
this is the code for paint event which i have used
@void ofi_vc_gui_panel::paintEvent (QPaintEvent *event)
{
QPainter paint(this); // Create a paint object.// Store the source rect of the image. QRect source = QRect(0, 0, dlg_data.cx, dlg_data.cy); // Store the target rect where image is to be drawn. QRect target = QRect(0, 0, dlg_data.cx, dlg_data.cy); // Draw the image. paint.drawPixmap (target, pixmap, source); i++; qDebug ()<<"event"<<i;
}
@ -
[quote author="Andre" date="1325150742"]How about you start out with a call to <code>QWidget::paintEvent(event);</code> 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. [/quote]
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.
-
[quote author="Andre" date="1325158806"]No, I do not have a mac.[/quote]
now the problem is little bit solved. I was using Qmainwindow as a child of other QMainwindow. So the problem was coming. Now i have replaced child window with Qmdisubwindow so the painting problem is now solved. Does it is necessary to keep Qmdisubwindow in Qmdiarea or we can use it independently?Now only one problem is there the focus rect which i have drawn for button is not appearing in mac. I am using Qstyleoption for that does i have to write different style for mac or there would be some other problem? This is the code which i am using for drawing rect
@
QStyleOptionFocusRect option;
if (this->hasFocus ()) {// Draw the focus frame for the widget having focus. this->style()->drawPrimitive(QStyle::PE_FrameFocusRect, &option, &painter, this); }@
-
-
An MDI subwindow is meant to be used in an MDI area. There's no gain to use it outside. And a main window as child of something else is pure nonsense. As is every window - those are toplevel by design.
Why do you paint yourself at all? What is wrong with the default provided widgets?