Change height and icon position of QToolBox tabs, using proxys

风流意气都作罢 提交于 2020-01-05 08:07:25

问题


Ok, so I want to customize the height and the position of icons of the tabs from a QToolBox widget. I am not able to do it using stylesheet (I tried different options, but none worked, see question: Customizing QToolBox: tab height), so I decided to give it a try to using a proxy. I know there are the controlElements:

    CE_ToolBar
    CE_ToolBoxTabShape
    CE_ToolBoxTabLabel

And so I can use them on the drawControl function to get what I want.

void drawControl(ControlElement oCtrElement,
            const QStyleOption *poStyleOptionption,
            QPainter *poPainter,
            const QWidget *poWidget) const

But I am not sure how to implement it... Any help or example? Thanks,


UPDATE: I have created the proxy, assigned it to the qtoolbox and added conditions to see if I could do something:

    ...
    ToolBoxProxy* tabStyle = new ToolBoxProxy();
    ui->toolBox->setStyle(tabStyle);
    ...

toolboxproxy.h

#include <QProxyStyle>
#include <QPainter>

class ToolBoxProxy : public QProxyStyle
{
public:

    explicit ToolBoxProxy();
    void drawControl(ControlElement oCtrElement, const QStyleOption *             poStylrOptionption, QPainter * poPainter, const QWidget * poWidget = 0) const;

};

toolboxproxy.cpp

#include "toolboxproxy.h"
#include <QDebug>

ToolBoxProxy::ToolBoxProxy(){

}

void ToolBoxProxy::drawControl(ControlElement oCtrElement, const QStyleOption *poStyleOptionption, QPainter *poPainter, const QWidget *poWidget) const
{
    if (oCtrElement == CE_ToolBar) {
        qDebug() << "CE_ToolBar";

    } else if (oCtrElement == CE_ToolBoxTabShape) {
        qDebug() << "CE_TOOLBOXTABSHAPE";

    } else if (oCtrElement == CE_ToolBoxTabLabel) {
        qDebug() << "CE_ToolBoxTabLabel";

    }
    QProxyStyle::drawControl(oCtrElement, poStyleOptionption, poPainter, poWidget);
}

I don't know why, but the software never prints out any of the 3 qDebug()... but if I set a breakpoint, it only reaches the function when the control element is any of those:

CE_ItemViewItem
CE_ShapedFrame
CE_ToolButtonLabel

来源:https://stackoverflow.com/questions/48805982/change-height-and-icon-position-of-qtoolbox-tabs-using-proxys

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!