-
Notifications
You must be signed in to change notification settings - Fork 41
Open
Description
I'm trying to understand where in the code I should try to rewrite the spacing/sizing definition in order to get a more natural spaces.
With current code, this is what we get:

auto tb0 = new QToolButton;
tb0->setText("Just text");
auto tb1 = new QToolButton;
tb1->setText("Just text");
tb1->setIcon(w->style()->standardIcon(QStyle::SP_DesktopIcon));
tb1->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);It looks like the total extra spacing is calculated correctly (the button's width could be ok) but the distribution between the 3 spacing (left, middle, right) is wrong.
Looking at forks, I was hoping @vladimir-kraus or @jcelerier could show me the way :)
As far as I know, it starts here:
phantomstyle/src/phantom/phantomstyle.cpp
Lines 4029 to 4034 in 309c97a
| case CC_ToolButton: { | |
| auto tbopt = qstyleoption_cast<const QStyleOptionToolButton*>(option); | |
| if (Ph::AllowToolBarAutoRaise || !tbopt || !widget || !widget->parent() || | |
| !widget->parent()->inherits("QToolBar")) { | |
| QCommonStyle::drawComplexControl(control, option, painter, widget); | |
| break; |
Then
QCommonStyle::drawComplexControl() will call proxy()->drawControl(CE_ToolButtonLabel, &label, p, widget) which is not handled by PhantomStyle, so it will default to QCommonStyle::drawControl(element, option, painter, widget)
The icon is drawn here (note the comment)
pr.setWidth(pmSize.width() + 4); //### 4 is currently hardcoded in QToolButton::sizeHint()
tr.adjust(pr.width(), 0, 0, 0);
pr.translate(shiftX, shiftY);
if (!hasArrow) {
proxy()->drawItemPixmap(p, QStyle::visualRect(opt->direction, rect, pr), Qt::AlignCenter, pm);PhantomStyle::drawItemPixmap() will call QCommonStyle::drawItemPixmap()
Then the text is drawn here
tr.translate(shiftX, shiftY);
const QString text = d->toolButtonElideText(toolbutton, tr, alignment);
proxy()->drawItemText(p, QStyle::visualRect(opt->direction, rect, tr), alignment, toolbutton->palette,
toolbutton->state & State_Enabled, text,
QPalette::ButtonText);Which will be handled by PhantomStyle::drawItemText()
gAdrev
Metadata
Metadata
Assignees
Labels
No labels