C++ (Qt)QLineEdit * QAbstractSpinBox::lineEdit () const [protected]
C++ (Qt)class MySpinBox : public QSpinBox{ Q_OBJECT public: MySpinBox(QWidget* parent = 0); protected: void paintEvent(QPaintEvent* event); private: QToolButton *m_btnUp; QToolButton *m_btnDown;};
C++ (Qt)MySpinBox::MySpinBox(QWidget* parent) : QSpinBox(parent){ setButtonSymbols(QAbstractSpinBox::NoButtons); m_btnUp = new QToolButton(this); m_btnUp->setText("+"); connect(m_btnUp, SIGNAL(clicked()), this, SLOT(stepUp())); m_btnDown = new QToolButton(this); m_btnDown->setText("-"); connect(m_btnDown, SIGNAL(clicked()), this, SLOT(stepDown()));} void MySpinBox::paintEvent(QPaintEvent* event){ QStyleOptionSpinBox opt; initStyleOption(&opt); QStylePainter p(this); m_btnDown->setGeometry(opt.rect.x(), opt.rect.y(), 20, opt.rect.height()); opt.rect = QRect(opt.rect.x()+20, opt.rect.y(), opt.rect.width()-40, opt.rect.height()); opt.frame = hasFrame(); m_btnUp->setGeometry(opt.rect.x() + opt.rect.width(), opt.rect.y(), 20, opt.rect.height()); lineEdit()->setGeometry(opt.rect.x()+2, opt.rect.y()+2, opt.rect.width()-4, opt.rect.height()-4); p.drawComplexControl(QStyle::CC_SpinBox, opt);}
C++ (Qt)QRect MyStyle::subControlRect ( ComplexControl control, const QStyleOptionComplex * option, SubControl subControl, const QWidget * widget ){ if ( control == CC_SpinBox ) { if ( subControl == SC_SpinBoxUp ) return QRect( ... ); if ( subControl == SC_SpinBoxDown ) return QRect( ... ); } return ParentStyle::subControlRect( control, option, subControl, widget );}
BigSpinBox::BigSpinBox( QWidget * parent ) : QSpinBox( parent ){ back = new QPushButton( "<" ) ; layout()->addWidget( back ) ; // Здесь происходит Segmentation fault}
class BigSpinBox : public QSpinBox{ Q_OBJECT public : BigSpinBox( QWidget * parent = 0 ) ; private : QPushButton * back ; QPushButton * forward ;} ;