PDA

View Full Version : QStyle porting problem



batileon
14th July 2008, 03:33
I have the following codes in QT3

QStyle::SFlags flags = QStyle::Style_Default;
if ( isEnabled() )
flags |= QStyle::Style_Enabled;
if ( isChecked() )
flags |= QStyle::Style_On;
else
flags |= QStyle::Style_Off;
if ( isEnabled() && table()->isEnabled() )
flags |= QStyle::Style_Enabled;

table()->style().drawPrimitive( QStyle::PE_Indicator, p,
QRect( 0, ( cr.height() - sz.height() ) / 2, sz.width(), sz.height() ), c, flags );
where p is QPainter*, c is QColorGroup, cr is QRect, sz=QSize

What should I do to convert it in QT4?

wysota
14th July 2008, 07:46
You have to fill (using initFrom() and setting the rect properly) and use an appropriate QStyleOption subclass.

batileon
14th July 2008, 09:22
I found that there's a new api which includes the QStyleOption
But how can I set the QStyleOption ?

wysota
14th July 2008, 10:14
As I said, use QStyleOption::initFrom() and fill all the other needed fields manually.

batileon
14th July 2008, 11:46
QStyleOption::initFrom(QWidget*)
What should the QWidget be????

Sorry, I m confused.
In the past we set the state like the code I posted, but for the QStyleOption, is that we can only obtain the values, but cannot set it?

jpn
14th July 2008, 12:23
QStyleOption::initFrom(QWidget*)
What should the QWidget be????

The widget you want to init the style option for. It initializes the state, direction, rect, palette, and fontMetrics member variables based on the specified widget.



Sorry, I m confused.
In the past we set the state like the code I posted, but for the QStyleOption, is that we can only obtain the values, but cannot set it?
Those "values" of QStyleOption are just public variables.

batileon
15th July 2008, 03:17
For example, if I'm drawing a self-defined class which inherits Q3CheckTableItem, what should I do?
Like this?

QStyleOption* qso = new QStyleOption();
qso->state = flags;
qso->rect = QRect( 0, ( cr.height() - sz.height() ) / 2, sz.width(), sz.height() );
(table()->style())->drawPrimitive( QStyle::PE_IndicatorCheckBox, qso, p );

What should I deal with the initFrom?
like this?(the code is in the self defined class)

qso->initFrom((QWidget *) this );
I tried this but this lead to segmentation fault.........

wysota
15th July 2008, 07:50
Q3CheckTableItem is not a widget. It's table is a widget though, so use it.

batileon
15th July 2008, 08:17
like this?

qso->initFrom((QWidget *) table() );

work for compilation...... but seems still can't solve my problem.
Actually my problem is that I found that the check box of the CheckTableItem disappeared after porting from qt3 to qt4.

And seems this is the only change I've made.......
Can anyone suggest where the problem is?

batileon
16th July 2008, 04:02
Problem solved.
I found that the new API need a QStyleOption *
However I found that a QStyleOptionButton * can show the checkbox but not a QStyleOption *

wysota
16th July 2008, 10:07
I told you to use the "appropriate QStyleOption subclass" not QStyleOption itself.

batileon
16th July 2008, 10:33
Thanks!!!
I m not familiar with these stuffs........
thank you for your support!