1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| #include "VCombo.h"
#include <QStylePainter>
#include <QAbstractItemView>
VCombo::VCombo ( QWidget * parent): QComboBox(parent)
{
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::MinimumExpanding);
}
QSize VCombo::sizeHint() const
{
const QSize s = QComboBox::sizeHint();
return QSize( s.height(), s.width() );
}
QSize VCombo::minimumSizeHint() const
{
const QSize s = QComboBox::minimumSizeHint();
return QSize( s.height(), s.width() + s.height() );
}
void VCombo::paintEvent( QPaintEvent *)
{
QStylePainter painter(this);
const int h = height() ;
painter.rotate( -90. );
painter.translate( QPointF(-h,0));
painter.setPen(palette().color(QPalette::Text));
// draw the combobox frame, focusrect and selected etc.
QStyleOptionComboBox opt;
initStyleOption(&opt);
const int tmp = opt.rect.width();
opt.rect.setWidth( opt.rect.height() );
opt.rect.setHeight( tmp );
painter.drawComplexControl(QStyle::CC_ComboBox, opt);
// draw the icon and text
painter.drawControl(QStyle::CE_ComboBoxLabel, opt);
} |