15 #include <qstyleoption.h>
31 QStyleOptionButton option;
32 option.initFrom( btn );
33 option.features = QStyleOptionButton::None;
35 option.features |= QStyleOptionButton::Flat;
37 option.features |= QStyleOptionButton::HasMenu;
38 if ( btn->autoDefault() || btn->isDefault() )
39 option.features |= QStyleOptionButton::AutoDefaultButton;
40 if ( btn->isDefault() )
41 option.features |= QStyleOptionButton::DefaultButton;
43 option.state |= QStyle::State_Sunken;
44 if ( !btn->isFlat() && !btn->isDown() )
45 option.state |= QStyle::State_Raised;
56 : QPushButton( parent )
62 setAutoRepeat(
true );
63 setAutoDefault(
false );
69 setSizePolicy( QSizePolicy::Expanding,
73 setSizePolicy( QSizePolicy::Fixed,
74 QSizePolicy::Expanding );
109 r.setRect( r.x() + m, r.y() + m,
110 r.width() - 2 * m, r.height() - 2 * m );
114 QStyleOptionButton option =
styleOpt(
this );
115 const int ph = style()->pixelMetric(
116 QStyle::PM_ButtonShiftHorizontal, &option,
this );
117 const int pv = style()->pixelMetric(
118 QStyle::PM_ButtonShiftVertical, &option,
this );
120 r.translate( ph, pv );
132 QPushButton::paintEvent( event );
133 QPainter painter(
this );
151 boundingSize.transpose();
157 QSize( w, boundingSize.height() ) );
165 contentsSize.setWidth(
m_data->
num * arrow.width()
167 contentsSize.setHeight( arrow.height() );
171 contentsSize.setWidth( arrow.width() );
172 contentsSize.setHeight(
m_data->
num * arrow.height()
176 QRect arrowRect( contentsSize );
177 arrowRect.moveCenter( r.center() );
178 arrowRect.setSize( arrow );
193 arrowRect.translate( dx, dy );
199 QStyleOptionFocusRect option;
200 option.initFrom(
this );
201 option.backgroundColor = palette().color( QPalette::Window );
203 style()->drawPrimitive( QStyle::PE_FrameFocusRect,
204 &option, painter,
this );
216 const QRect& r, Qt::ArrowType arrowType )
const
223 pa.setPoint( 0, r.bottomLeft() );
224 pa.setPoint( 1, r.bottomRight() );
225 pa.setPoint( 2, r.center().x(), r.top() );
228 pa.setPoint( 0, r.topLeft() );
229 pa.setPoint( 1, r.topRight() );
230 pa.setPoint( 2, r.center().x(), r.bottom() );
233 pa.setPoint( 0, r.topLeft() );
234 pa.setPoint( 1, r.bottomLeft() );
235 pa.setPoint( 2, r.right(), r.center().y() );
238 pa.setPoint( 0, r.topRight() );
239 pa.setPoint( 1, r.bottomRight() );
240 pa.setPoint( 2, r.left(), r.center().y() );
248 painter->setRenderHint( QPainter::Antialiasing,
true );
249 painter->setPen( Qt::NoPen );
250 painter->setBrush( palette().brush( QPalette::ButtonText ) );
251 painter->drawPolygon( pa );
270 const QSize asz =
arrowSize( Qt::RightArrow, QSize() );
280 QStyleOption styleOption;
281 styleOption.initFrom(
this );
283 sz = style()->sizeFromContents( QStyle::CT_PushButton,
284 &styleOption, sz,
this );
297 const QSize& boundingSize )
const
299 QSize bs = boundingSize;
303 const int MinLen = 2;
304 const QSize sz = bs.expandedTo(
305 QSize( MinLen, 2 * MinLen - 1 ) );
310 if ( h > sz.height() )
316 QSize arrSize( w, h );
328 if ( event->isAutoRepeat() && event->key() == Qt::Key_Space )
331 QPushButton::keyPressEvent( event );