Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 4

Qt-interest Archive, December 2006
Drawing a pushbutton


Message 1 in thread

Hi,
 
I want to draw a button using QStyle class. I am writing this code:
 
QApplication app(argc, argv);
QWidget *widget = new QWidget;
QStyleOptionButton callbutton;
callbutton.icon = QIcon("btn_conference.png");
callbutton.text="here";
QPainter painter(widget);
QApplication::style()->drawControl(QStyle::CE_PushButton, &callbutton,
&painter,widget);
widget->show();
return app.exec();

but i dont see any thing on window. What am I do wrong?

thanks.

--
 [ signature omitted ] 

Message 2 in thread

Jaya Meghani wrote:
> Hi,
>  
> I want to draw a button using QStyle class. I am writing this code:
>  
> QApplication app(argc, argv);
> QWidget *widget = new QWidget;
> QStyleOptionButton callbutton;
> callbutton.icon = QIcon("btn_conference.png");
> callbutton.text="here";
> QPainter painter(widget);
> QApplication::style()->drawControl(QStyle::CE_PushButton, &callbutton,
> &painter,widget);
> widget->show();
> return app.exec();
>
> but i dont see any thing on window. What am I do wrong?
>
>   

In Qt4 you cannot paint widgets outside of a paint event.  This should 
cause runtime errors printed to stderr.  You should subclass QWidget and 
try the same type of code in an overloaded paintEvent(QPaintEvent*) method.

--Justin
begin:vcard
begin:vcard
fn:Justin Noel
n:Noel;Justin
org:ICS;Engineering
adr:;;54B Middlesex Trpk;Bedford;MA;01730;USA
email;internet:justin@xxxxxxx
title:Sr. Consulting Engineer / Certified Qt Instructor
tel;work:(617) 621-0060
url:http://www.ics.com
version:2.1
end:vcard


Message 3 in thread

Thanks for reply.

I have a TreeWidget Delegate. Can I paint on TreeWidget in delegate's
paint() call?
If yes then I do something like this.

I have another class QTReagent(derived from QObject) which I call from
paint() of delegate

void QtTreeViewDelegate::paint(QPainter * painter, const
QStyleOptionViewItem & option, const QModelIndex & index) const {
............
If(status)
	reagent->paint(painter, option, index);
.............

}

Reagent's parent is QTreeWidget.

In Reagent classes paint function I right:

void QTReagent::paint(QPainter * painter, const QStyleOptionViewItem &
option, const QModelIndex &index ) {

........
Load px_image
...........

		QStyleOptionButton chatButton;
		chatButton.icon = QIcon(px_image);
		chatButton.text = "Test"; 
		QWidget * parent_Widget = dynamic_cast <QWidget *>
(parent());
	
parent_Widget->style()->drawControl(QStyle::CE_PushButton, &chatButton,
painter);
}

But I still see no icon (px_image) or text (Test)...what should I do?

Thanks.



-----Original Message-----
From: Justin Noel [mailto:justin@xxxxxxx] 
Sent: Tuesday, December 19, 2006 4:03 PM
To: qt-interest@xxxxxxxxxxxxx
Subject: Re: Drawing a pushbutton

Jaya Meghani wrote:
> Hi,
>  
> I want to draw a button using QStyle class. I am writing this code:
>  
> QApplication app(argc, argv);
> QWidget *widget = new QWidget;
> QStyleOptionButton callbutton;
> callbutton.icon = QIcon("btn_conference.png"); callbutton.text="here";

> QPainter painter(widget); 
> QApplication::style()->drawControl(QStyle::CE_PushButton, &callbutton,

> &painter,widget);
> widget->show();
> return app.exec();
>
> but i dont see any thing on window. What am I do wrong?
>
>   

In Qt4 you cannot paint widgets outside of a paint event.  This should
cause runtime errors printed to stderr.  You should subclass QWidget and
try the same type of code in an overloaded paintEvent(QPaintEvent*)
method.

--Justin

--
 [ signature omitted ] 

Message 4 in thread

Jaya Meghani wrote:
> Thanks for reply.
>
> I have a TreeWidget Delegate. Can I paint on TreeWidget in delegate's
> paint() call?
>   
Yes, you can paint in paint().

> If yes then I do something like this.
>
> I have another class QTReagent(derived from QObject) which I call from
> paint() of delegate
>
> void QtTreeViewDelegate::paint(QPainter * painter, const
> QStyleOptionViewItem & option, const QModelIndex & index) const {
> ............
> If(status)
> 	reagent->paint(painter, option, index);
> .............
>
> }
>
> Reagent's parent is QTreeWidget.
>
> In Reagent classes paint function I right:
>
> void QTReagent::paint(QPainter * painter, const QStyleOptionViewItem &
> option, const QModelIndex &index ) {
>
> ........
> Load px_image
> ...........
>
> 		QStyleOptionButton chatButton;
> 		chatButton.icon = QIcon(px_image);
> 		chatButton.text = "Test"; 
> 		QWidget * parent_Widget = dynamic_cast <QWidget *>
> (parent());
> 	
> parent_Widget->style()->drawControl(QStyle::CE_PushButton, &chatButton,
> painter);
> }
>
> But I still see no icon (px_image) or text (Test)...what should I do?
>
> Thanks.
>
>
>
> -

You might need to fill out the rest of the option structure that you 
inherited from QStyleOption.  This includes the drawing rectangle and 
palette.  You can use the values from the QStyleOptionViewItem*.

--Justin
begin:vcard
begin:vcard
fn:Justin Noel
n:Noel;Justin
org:ICS;Engineering
adr:;;54B Middlesex Trpk;Bedford;MA;01730;USA
email;internet:justin@xxxxxxx
title:Sr. Consulting Engineer / Certified Qt Instructor
tel;work:(617) 621-0060
url:http://www.ics.com
version:2.1
end:vcard


Message 5 in thread

Hi Justin,

I had recently the same kind of problem, seems.

I am quite sure you'll find my samplecode on the recent thread
http://lists.trolltech.com/qt-interest/2006-12/thread00210-0.html
helpful ;=)

You'll find two version of the sample code there.
I may post a more recent one soon.

Best-
Nicolas


Justin Noel wrote:

> Jaya Meghani wrote:
>> Thanks for reply.
>>
>> I have a TreeWidget Delegate. Can I paint on TreeWidget in delegate's
>> paint() call?
>>   
> Yes, you can paint in paint().
> 
>> If yes then I do something like this.
>>
>> I have another class QTReagent(derived from QObject) which I call from
>> paint() of delegate
>>
>> void QtTreeViewDelegate::paint(QPainter * painter, const
>> QStyleOptionViewItem & option, const QModelIndex & index) const {
>> ............
>> If(status)
>> reagent->paint(painter, option, index);
>> .............
>>
>> }
>>
>> Reagent's parent is QTreeWidget.
>>
>> In Reagent classes paint function I right:
>>
>> void QTReagent::paint(QPainter * painter, const QStyleOptionViewItem &
>> option, const QModelIndex &index ) {
>>
>> ........
>> Load px_image
>> ...........
>>
>> QStyleOptionButton chatButton;
>> chatButton.icon = QIcon(px_image);
>> chatButton.text = "Test";
>> QWidget * parent_Widget = dynamic_cast <QWidget *>
>> (parent());
>> 
>> parent_Widget->style()->drawControl(QStyle::CE_PushButton, &chatButton,
>> painter);
>> }
>>
>> But I still see no icon (px_image) or text (Test)...what should I do?
>>
>> Thanks.
>>
>>
>>
>> -
> 
> You might need to fill out the rest of the option structure that you
> inherited from QStyleOption.  This includes the drawing rectangle and
> palette.  You can use the values from the QStyleOptionViewItem*.
> 
> --Justin

--
 [ signature omitted ] 

Message 6 in thread

I am not sure you can call delegate::paint() directly, since the delegate is
not a widget but a view's facility 

Pbly, delegate::paint() should be called from the view's paintEvent().

Hence, you 'd pbly better ask the view to repaint one of its QModelIndex.

To request the view repaint a model index call update(QRect).

Best-
Nicolas

Jaya Meghani wrote:

> Thanks for reply.
> 
> I have a TreeWidget Delegate. Can I paint on TreeWidget in delegate's
> paint() call?
> If yes then I do something like this.
> 
> I have another class QTReagent(derived from QObject) which I call from
> paint() of delegate
> 
> void QtTreeViewDelegate::paint(QPainter * painter, const
> QStyleOptionViewItem & option, const QModelIndex & index) const {
> ............
> If(status)
> reagent->paint(painter, option, index);
> .............
> 
> }
> 
> Reagent's parent is QTreeWidget.
> 
> In Reagent classes paint function I right:
> 
> void QTReagent::paint(QPainter * painter, const QStyleOptionViewItem &
> option, const QModelIndex &index ) {
> 
> ........
> Load px_image
> ...........
> 
> QStyleOptionButton chatButton;
> chatButton.icon = QIcon(px_image);
> chatButton.text = "Test";
> QWidget * parent_Widget = dynamic_cast <QWidget *>
> (parent());
> 
> parent_Widget->style()->drawControl(QStyle::CE_PushButton, &chatButton,
> painter);
> }
> 
> But I still see no icon (px_image) or text (Test)...what should I do?
> 
> Thanks.
> 
> 
> 
> -----Original Message-----
> From: Justin Noel [mailto:justin@xxxxxxx]
> Sent: Tuesday, December 19, 2006 4:03 PM
> To: qt-interest@xxxxxxxxxxxxx
> Subject: Re: Drawing a pushbutton
> 
> Jaya Meghani wrote:
>> Hi,
>>  
>> I want to draw a button using QStyle class. I am writing this code:
>>  
>> QApplication app(argc, argv);
>> QWidget *widget = new QWidget;
>> QStyleOptionButton callbutton;
>> callbutton.icon = QIcon("btn_conference.png"); callbutton.text="here";
> 
>> QPainter painter(widget);
>> QApplication::style()->drawControl(QStyle::CE_PushButton, &callbutton,
> 
>> &painter,widget);
>> widget->show();
>> return app.exec();
>>
>> but i dont see any thing on window. What am I do wrong?
>>
>>   
> 
> In Qt4 you cannot paint widgets outside of a paint event.  This should
> cause runtime errors printed to stderr.  You should subclass QWidget and
> try the same type of code in an overloaded paintEvent(QPaintEvent*)
> method.
> 
> --Justin
> 
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body. List archive and information:
> http://lists.trolltech.com/qt-interest/

--
 [ signature omitted ] 

Message 7 in thread

Nicolas Castagne wrote:

> I am not sure you can call delegate::paint() directly, since the delegate
> is not a widget but a view's facility
> 
> Pbly, delegate::paint() should be called from the view's paintEvent().
> 
> Hence, you 'd pbly better ask the view to repaint one of its QModelIndex.
> 
> To request the view repaint a model index call update(QRect).
> 
> Best-
> Nicolas

Oups !
Indeed, I guess the update(QRect) should be called on the view's viewport,
instead of on directly on the view.

Mistake, sry...

Best-



> 
> Jaya Meghani wrote:
> 
>> Thanks for reply.
>> 
>> I have a TreeWidget Delegate. Can I paint on TreeWidget in delegate's
>> paint() call?
>> If yes then I do something like this.
>> 
>> I have another class QTReagent(derived from QObject) which I call from
>> paint() of delegate
>> 
>> void QtTreeViewDelegate::paint(QPainter * painter, const
>> QStyleOptionViewItem & option, const QModelIndex & index) const {
>> ............
>> If(status)
>> reagent->paint(painter, option, index);
>> .............
>> 
>> }
>> 
>> Reagent's parent is QTreeWidget.
>> 
>> In Reagent classes paint function I right:
>> 
>> void QTReagent::paint(QPainter * painter, const QStyleOptionViewItem &
>> option, const QModelIndex &index ) {
>> 
>> ........
>> Load px_image
>> ...........
>> 
>> QStyleOptionButton chatButton;
>> chatButton.icon = QIcon(px_image);
>> chatButton.text = "Test";
>> QWidget * parent_Widget = dynamic_cast <QWidget *>
>> (parent());
>> 
>> parent_Widget->style()->drawControl(QStyle::CE_PushButton, &chatButton,
>> painter);
>> }
>> 
>> But I still see no icon (px_image) or text (Test)...what should I do?
>> 
>> Thanks.
>> 
>> 
>> 
>> -----Original Message-----
>> From: Justin Noel [mailto:justin@xxxxxxx]
>> Sent: Tuesday, December 19, 2006 4:03 PM
>> To: qt-interest@xxxxxxxxxxxxx
>> Subject: Re: Drawing a pushbutton
>> 
>> Jaya Meghani wrote:
>>> Hi,
>>>  
>>> I want to draw a button using QStyle class. I am writing this code:
>>>  
>>> QApplication app(argc, argv);
>>> QWidget *widget = new QWidget;
>>> QStyleOptionButton callbutton;
>>> callbutton.icon = QIcon("btn_conference.png"); callbutton.text="here";
>> 
>>> QPainter painter(widget);
>>> QApplication::style()->drawControl(QStyle::CE_PushButton, &callbutton,
>> 
>>> &painter,widget);
>>> widget->show();
>>> return app.exec();
>>>
>>> but i dont see any thing on window. What am I do wrong?
>>>
>>>   
>> 
>> In Qt4 you cannot paint widgets outside of a paint event.  This should
>> cause runtime errors printed to stderr.  You should subclass QWidget and
>> try the same type of code in an overloaded paintEvent(QPaintEvent*)
>> method.
>> 
>> --Justin
>> 
>> --
>> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
>> "unsubscribe" in the subject or the body. List archive and information:
>> http://lists.trolltech.com/qt-interest/

--
 [ signature omitted ] 

Message 8 in thread

Justin,Nicholas
Thanks for help.

Nicholas,

I am NOT able to download widgets_in_view.tar file...can you please mail
me.

Thanks,
Jaya

-----Original Message-----
From: Nicolas Castagne [mailto:castagne@xxxxxxx] 
Sent: Wednesday, December 20, 2006 4:21 AM
To: qt-interest@xxxxxxxxxxxxx
Subject: RE: Drawing a pushbutton

Nicolas Castagne wrote:

> I am not sure you can call delegate::paint() directly, since the 
> delegate is not a widget but a view's facility
> 
> Pbly, delegate::paint() should be called from the view's paintEvent().
> 
> Hence, you 'd pbly better ask the view to repaint one of its
QModelIndex.
> 
> To request the view repaint a model index call update(QRect).
> 
> Best-
> Nicolas

Oups !
Indeed, I guess the update(QRect) should be called on the view's
viewport, instead of on directly on the view.

Mistake, sry...

Best-



> 
> Jaya Meghani wrote:
> 
>> Thanks for reply.
>> 
>> I have a TreeWidget Delegate. Can I paint on TreeWidget in delegate's
>> paint() call?
>> If yes then I do something like this.
>> 
>> I have another class QTReagent(derived from QObject) which I call 
>> from
>> paint() of delegate
>> 
>> void QtTreeViewDelegate::paint(QPainter * painter, const 
>> QStyleOptionViewItem & option, const QModelIndex & index) const { 
>> ............
>> If(status)
>> reagent->paint(painter, option, index);
>> .............
>> 
>> }
>> 
>> Reagent's parent is QTreeWidget.
>> 
>> In Reagent classes paint function I right:
>> 
>> void QTReagent::paint(QPainter * painter, const QStyleOptionViewItem 
>> & option, const QModelIndex &index ) {
>> 
>> ........
>> Load px_image
>> ...........
>> 
>> QStyleOptionButton chatButton;
>> chatButton.icon = QIcon(px_image);
>> chatButton.text = "Test";
>> QWidget * parent_Widget = dynamic_cast <QWidget *> (parent());
>> 
>> parent_Widget->style()->drawControl(QStyle::CE_PushButton, 
>> &chatButton, painter); }
>> 
>> But I still see no icon (px_image) or text (Test)...what should I do?
>> 
>> Thanks.
>> 
>> 
>> 
>> -----Original Message-----
>> From: Justin Noel [mailto:justin@xxxxxxx]
>> Sent: Tuesday, December 19, 2006 4:03 PM
>> To: qt-interest@xxxxxxxxxxxxx
>> Subject: Re: Drawing a pushbutton
>> 
>> Jaya Meghani wrote:
>>> Hi,
>>>  
>>> I want to draw a button using QStyle class. I am writing this code:
>>>  
>>> QApplication app(argc, argv);
>>> QWidget *widget = new QWidget;
>>> QStyleOptionButton callbutton;
>>> callbutton.icon = QIcon("btn_conference.png"); 
>>> callbutton.text="here";
>> 
>>> QPainter painter(widget);
>>> QApplication::style()->drawControl(QStyle::CE_PushButton, 
>>> &callbutton,
>> 
>>> &painter,widget);
>>> widget->show();
>>> return app.exec();
>>>
>>> but i dont see any thing on window. What am I do wrong?
>>>
>>>   
>> 
>> In Qt4 you cannot paint widgets outside of a paint event.  This 
>> should cause runtime errors printed to stderr.  You should subclass 
>> QWidget and try the same type of code in an overloaded 
>> paintEvent(QPaintEvent*) method.
>> 
>> --Justin
>> 
>> --
>> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx 
>> with "unsubscribe" in the subject or the body. List archive and
information:
>> http://lists.trolltech.com/qt-interest/

--
 [ signature omitted ]