PDA

View Full Version : Size of button



baray98
3rd January 2008, 19:19
Hi All,

I have made a delegate that will display a button at on every item in my QTreeView. I have provided the size hint of my button properly. What i want to accomplish is that I want my button to have a constant size, Since my treemodel contains only 1 column my button will increase/decrease according to width of my coloumn which I dont want to happen. How can i prevent this from happening?

Note:
I was painting the button its not a composite widget so i dont have size policy

heres the code when i paint it


void MyDelegate::paint(QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
const QAbstractItemModel *model = index.model();
Q_ASSERT(model);

if (qVariantCanConvert<MyCustomsClass>(index.data(MyModel::DeviceInfoRole)))
{
MyCustomsClass info = qVariantValue<MyCustomsClass>(index.data(MyModel::DeviceInfoRole));
QStyleOptionButton buttonOption;

buttonOption.state = option.state;
#ifdef Q_WS_MAC
buttonOption.state |= QStyle::State_Raised;
#endif
buttonOption.state &= ~QStyle::State_HasFocus;

buttonOption.rect = option.rect ;
buttonOption.palette = option.palette;
buttonOption.features = QStyleOptionButton::None;
m_view->style()->drawControl(QStyle::CE_PushButton, &buttonOption, painter, m_view);

QStyleOption branchOption;
static const int i = 9; // ### hardcoded in qcommonstyle.cpp

QRect r = option.rect;

branchOption.rect = QRect(r.left() + i/2, r.top() + (r.height() - i)/2, i, i);
branchOption.palette = option.palette;
branchOption.state = QStyle::State_Children;

// draw text
QRect textrect = QRect(r.left() + i*2, r.top(), r.width() - ((5*i)/2), r.height());
QString text = elidedText(option.fontMetrics, textrect.width(), Qt::ElideMiddle,
info .name());
m_view->style()->drawItemText(painter, textrect, Qt::AlignCenter,
option.palette, m_view->isEnabled(), text);



}
}


baray98

jacek
3rd January 2008, 22:04
What is buttonOption.rect responsible for?