自定义QMenu图标大小

版权声明:http://blog.csdn.net/robertkun https://blog.csdn.net/robertkun/article/details/38117413


上代码:

///////////////////////////////////////////////////////////
// QMenu的大图标定义
///////////////////////////////////////////////////////////

#ifndef CUSTOMICONSTYLE_H
#define CUSTOMICONSTYLE_H

#include <QCommonStyle>

class CustomIconStyle : public QCommonStyle
{
	Q_OBJECT

public:
	CustomIconStyle();
	~CustomIconStyle();

	void SetCustomSize(int);

	//protected:
	virtual int pixelMetric(PixelMetric metric, const QStyleOption * option, const QWidget * widget) const;

private:
	int mSize;
};

#endif // CUSTOMICONSTYLE_H

#include "CustomIconStyle.h"

CustomIconStyle::CustomIconStyle()
{
	mSize = 20;
}

CustomIconStyle::~CustomIconStyle()
{

}


void CustomIconStyle::SetCustomSize( int nSize )
{
	mSize = nSize;
}

int CustomIconStyle::pixelMetric( PixelMetric metric, const QStyleOption * option, const QWidget * widget ) const
{
	int s = QCommonStyle::pixelMetric(metric, option, widget);
	if (metric == QStyle::PM_SmallIconSize) {
		s = mSize;
	}

	return s;
}

调用方法:

CustomIconStyle* pStyle = new CustomIconStyle;
	mpMikeMenu->setStyle(pStyle);


阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页