Qt-interest Archive, October 2007
QWidget painting question
Message 1 in thread
Hi! Suppose i've subclassed a QWidget class and make it visible using show()
function. according to a website:
http://developer.kde.org/documentation/books/kde-2.0-development/ch04lev1sec2.html
"The paintEvent() method is called automatically when
*Your widget is shown for the first time..."
I wanted to know where exactly it is. QWidget::show() calls QWidget::setVisible()
but setVisible() function neither call paintEvent() function directly nor does
it call through sending an event. Is it possible for someone to point out where
paintEvent() method get called when i first display my QWidget subclass using
QWidget::show() function? Thanks.
_________________________________________________________________
Are you ready for Windows Live Messenger Beta 8.5 ? Get the latest for free today!
http://entertainment.sympatico.msn.ca/WindowsLiveMessenger
--
[ signature omitted ]
Message 2 in thread
A D wrote:
> Hi! Suppose i've subclassed a QWidget class and make it visible using show()
> function. according to a website:
>
> http://developer.kde.org/documentation/books/kde-2.0-development/ch04lev1sec2.html
>
> "The paintEvent() method is called automatically when
>
> *Your widget is shown for the first time..."
>
> I wanted to know where exactly it is. QWidget::show() calls QWidget::setVisible()
reimplement QWidget::showEvent(....) function. and read the description
of that on docs.
http://doc.trolltech.com/4.3/qwidget.html#showEvent
- Adam
--
[ signature omitted ]
Message 3 in thread
I need to be able to pass an array/QList of a custom data type (representing
a complex number) between the script and my application
I am certain that this is achievable using the
qScriptRegisterSequenceMetaType<T> function.
However when I try this I am getting error
error C2039: 'qt_metatype_id' : is not a member of 'QMetaTypeId<T>'
with
[
T=QList<Complex>::value_type
]
I have declared the metatype using Q_DECLARE_METATYPE(QList<Complex>)
And am trying to register the sequence by
qScriptRegisterSequenceMetaType<QList<Complex> >(&engine_);
Im assuming that I am missing something, I just don't know what and havent
been able to find anything in the documentation.
Any help is appreciated
Regards,
Ben
--
[ signature omitted ]
Message 4 in thread
Ben Shaw wrote:
> I need to be able to pass an array/QList of a custom data type (representing
> a complex number) between the script and my application
> I am certain that this is achievable using the
> qScriptRegisterSequenceMetaType<T> function.
> However when I try this I am getting error
>
> error C2039: 'qt_metatype_id' : is not a member of 'QMetaTypeId<T>'
> with
> [
> T=QList<Complex>::value_type
> ]
>
> I have declared the metatype using Q_DECLARE_METATYPE(QList<Complex>)
> And am trying to register the sequence by
> qScriptRegisterSequenceMetaType<QList<Complex> >(&engine_);
> Im assuming that I am missing something, I just don't know what and havent
> been able to find anything in the documentation.
> Any help is appreciated
>
> Regards,
>
>
> Ben
>
Hi Ben,
Did you do a Q_DECLARE_METATYPE(Complex)?
Regards,
Kent
--
[ signature omitted ]
Message 5 in thread
> A D wrote:
> Hi! Suppose i've subclassed a QWidget class and make it visible using show()
> function. according to a website:
>
> http://developer.kde.org/documentation/books/kde-2.0-development/ch04lev1sec2.html
>
> "The paintEvent() method is called automatically when
>
> *Your widget is shown for the first time..."
>
> I wanted to know where exactly it is. QWidget::show() calls QWidget::setVisible()
>
>> Adam wrote:
>> reimplement QWidget::showEvent(....) function. and read the description
>> of that on docs.
>>
>> http://doc.trolltech.com/4.3/qwidget.html#showEvent
I think i didn't make myself clear. Sorry about that. Suppose we've code like this:
#include
#include
#include
#include
class MyWidget : public QWidget
{
public:
MyWidget(QWidget *parent = 0);
};
MyWidget::MyWidget(QWidget *parent)
: QWidget(parent)
{
setFixedSize(200, 120);
QPushButton *quit = new QPushButton(tr("Quit"), this);
quit->setGeometry(62, 40, 75, 30);
quit->setFont(QFont("Times", 18, QFont::Bold));
connect(quit, SIGNAL(clicked()), qApp, SLOT(quit()));
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MyWidget widget;
widget.show();
return app.exec();
}
My question is: in the example above when widget.show() is executed in order to
paint itself doesn't it(show() function) calls drawWidget() function directly or
indirectly? because i read in a website that when a widget, in this case an instance
of a subclass of QWidget, shows itself for the first time it needs to execute
paintEvent() function which is a handler(defined in qwidget.cpp) for QPaintEVent.
And the only place I can find this QPaintEvent sent to an instance of QWidget is in
drawWidget() function defined in qbackingstore.cpp
If the answer to my last question is yes where in the the definition of
QWidget's show() function, this drawWidget() function is called? I
looked into the source code I might've missed it. Is it possible to kindly state
the exact location where drawWidget() get called?
Thanks.
_________________________________________________________________
R U Ready for Windows Live Messenger Beta 8.5? Try it today!
http://entertainment.sympatico.msn.ca/WindowsLiveMessenger
--
[ signature omitted ]
Message 6 in thread
Hi,
Your link to the kde doco provides the answer in the very next paragraph!
Update adds a paint event to the event queue. Sometime later, the paint
event method is called by the event system (usually when there are no other
events in the queue).
Note that 'called automatically' does not imply 'called directly', as you
are assuming.
Why do you want to know where paintEvent is called from? What is the actual
problem that you are trying to solve?
You only need to override paintEvent if you are doing custom drawing.
Ordinary widgets, like the pushButton draw themselves.
Also, it's probably not a good idea to mix custom painted widgets with
ordinary ones - especially if you are just starting. Keep the custom painted
widget separate and use a container widget to combine it with the ordinary
ones.
Hope that helps,
Tony Rietwyk.
> -----Original Message-----
> From: A D [mailto:a_d_249@xxxxxxxxxxx]
> Sent: Wednesday, 24 October 2007 14:12
> To: qt-interest@xxxxxxxxxxxxx
> Subject: RE: QWidget painting question
>
<snip>
> indirectly? because i read in a website that when a widget,
> in this case an instance
> of a subclass of QWidget, shows itself for the first time it
> needs to execute
> paintEvent() function which is a handler(defined in
> qwidget.cpp) for QPaintEVent.
--
[ signature omitted ]
Message 7 in thread
>Rietwyk wrote:
>Hi,
>
>Your link to the kde doco provides the answer in the very next paragraph!
>Update adds a paint event to the event queue. Sometime later, the paint
>event method is called by the event system (usually when there are no other
>events in the queue).
>
>Note that 'called automatically' does not imply 'called directly', as you
>are assuming.
First of all thanks for your reply. The link to the doc i provided says:
"You can generate paint events manually by calling QWidget::update().
QWidget::update() erases the widget before generating the paint event."
"manually" is the keyword. So when paint event is needed I can manually
cause it to happen using update() function. But what happens when i call
widget.show() on an instance of QWidget? Does it call update() function?
If so Where in the qt source code QWidget::show() function calls update()
function? i can't find it.
>Why do you want to know where paintEvent is called from? What is the actual
>problem that you are trying to solve?
Just out of curiosity i wanted to know what really happens inside Qt and how
it works. Nothing else.
>You only need to override paintEvent if you are doing custom drawing.
>Ordinary widgets, like the pushButton draw themselves.
>
>Also, it's probably not a good idea to mix custom painted widgets with
>ordinary ones - especially if you are just starting. Keep the custom painted
>widget separate and use a container widget to combine it with the ordinary
>ones.
Thanks for the suggestion. I'll remember that..
_________________________________________________________________
Have fun while connecting on Messenger! Click here to learn more.
http://entertainment.sympatico.msn.ca/WindowsLiveMessenger
--
[ signature omitted ]