MyButton{
outline: none; /* remove focus rectangle */
text-overflow: ellipsis;
border-image: url(:/images/Resources/Images/Active.png) 9;
border: 9px transparent;
}
MyButton:selected {
border-image: url(:/images/Resources/Images/Selected.png) 9;
}
MyButton:focus {
border-image: url(:/images/Resources/Images/Focus.png) 9;
}
MyButton:hover {
border-image: url(:/images/Resources/Images/Focus.png) 9;
}
MyButton:pressed {
border-image: url(:/images/Resources/Images/Selected.png) 9;
}
MyButton{
outline: none; /* remove focus rectangle */
text-overflow: ellipsis;
border-image: url(:/images/Resources/Images/Active.png) 9;
border: 9px transparent;
}
MyButton:selected {
border-image: url(:/images/Resources/Images/Selected.png) 9;
}
MyButton:focus {
border-image: url(:/images/Resources/Images/Focus.png) 9;
}
MyButton:hover {
border-image: url(:/images/Resources/Images/Focus.png) 9;
}
MyButton:pressed {
border-image: url(:/images/Resources/Images/Selected.png) 9;
}
To copy to clipboard, switch view to plain text mode
{
QRect btnRect
= this
->rect
();
opt.init(this);
if (!this->icon().isNull() && !this->text().isEmpty()) {
//decrease the height of the drawing area so it doesn't cover the text
opt.rect.adjust(0,0,0,-(fontMetrics().height() * 2));
}
//draw the backround
style
()->drawPrimitive
(QStyle::PE_Widget,
&opt,
&p,
this);
/*
Tried adding this and removing the "outline: none;" from the style sheet with no affect
I added this with the conditional to verify that it was getting focus…
//draw the focus/selection rect
if (opt.state & QStyle::State_HasFocus) {
QStyleOptionFocusRect focusOpt;
focusOpt.QStyleOption::operator=(opt);
//focusOpt.state | QStyle::State_FocusAtBorder; // tried with and without – no change
style()->drawPrimitive(QStyle::PE_FrameFocusRect, &focusOpt, &p, this);
}
*/
if (!this->icon().isNull())
{
iconRect.setRect(10,10, opt.rect.width()-30, opt.rect.height()-20);
//Draw the icon
style()->drawItemPixmap(&p, iconRect, Qt::AlignLeft | Qt::AlignVCenter,
this->icon().pixmap(iconRect.size()));
if (!this->text().isEmpty()) {
opt.rect.adjust(0,0,0,fontMetrics().height() * 2);
// This button has an icon and text. The text should be drawn below
textRect.setRect(btnRect.x(),
45,
btnRect.width(),
fontMetrics().height() * 2);
style()->drawItemText(&p, textRect, Qt::AlignCenter, (this->palette()),
true, this
->text
(),
QPalette::ButtonText );
}
} else {
if (!this->text().isEmpty()) {
// this button has text but no icon
// Draw the text centered on the button
style()->drawItemText(&p, this->rect(), Qt::AlignCenter, (this->palette()),
true, this->text());
}
}
}
void MyPushButton::paintEvent ( QPaintEvent * pEvent )
{
QStyleOption opt;
QPainter p(this);
QRect iconRect;
QRect textRect;
QRect btnRect = this->rect();
opt.init(this);
if (!this->icon().isNull() && !this->text().isEmpty()) {
//decrease the height of the drawing area so it doesn't cover the text
opt.rect.adjust(0,0,0,-(fontMetrics().height() * 2));
}
//draw the backround
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
/*
Tried adding this and removing the "outline: none;" from the style sheet with no affect
I added this with the conditional to verify that it was getting focus…
//draw the focus/selection rect
if (opt.state & QStyle::State_HasFocus) {
QStyleOptionFocusRect focusOpt;
focusOpt.QStyleOption::operator=(opt);
//focusOpt.state | QStyle::State_FocusAtBorder; // tried with and without – no change
style()->drawPrimitive(QStyle::PE_FrameFocusRect, &focusOpt, &p, this);
}
*/
if (!this->icon().isNull())
{
iconRect.setRect(10,10, opt.rect.width()-30, opt.rect.height()-20);
//Draw the icon
style()->drawItemPixmap(&p, iconRect, Qt::AlignLeft | Qt::AlignVCenter,
this->icon().pixmap(iconRect.size()));
if (!this->text().isEmpty()) {
opt.rect.adjust(0,0,0,fontMetrics().height() * 2);
// This button has an icon and text. The text should be drawn below
textRect.setRect(btnRect.x(),
45,
btnRect.width(),
fontMetrics().height() * 2);
style()->drawItemText(&p, textRect, Qt::AlignCenter, (this->palette()),
true, this->text(), QPalette::ButtonText );
}
} else {
if (!this->text().isEmpty()) {
// this button has text but no icon
// Draw the text centered on the button
style()->drawItemText(&p, this->rect(), Qt::AlignCenter, (this->palette()),
true, this->text());
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks