子类化QWidget IconEditor实现

现在我们从iconEditor构造函数入手:

iconeditor::iconeditor(QWidget *parent) :
    QWidget(parent)
{
    setAttribute(Qt::WA_StaticContents);
    setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
    curColor = Qt::black;
    zoom = 8;
    image = QImage(16, 16, QImage::Format_ARGB32);
    image.fill(qRgba(0, 0, 0, 0));
}
 

setAttribute(Qt::WA_StaticConents);  

Qt::WA_StaticContents属性。
这个属性告诉Qt,当重新改变窗口部件大小时,这个窗口部件的内容并没有发生变化,而且它的内容仍旧保留从窗口左上角开始的特性。当重新定义窗口部件的大小时,通过使用这个信息,Qt就可以避免对已经显示区域的重新绘制。
       通常情况下,当重新定义一个窗口部件的大小时,Qt会为窗口部件的整个可见区域生成一个绘制事件。但是如果该窗口部件在创建时使用了Qt:: WA_StaticContents属性,那么绘制事件的区域就会被严格限定在之前没有被显示的像素部分上。这也就意味着,如果重新把窗口部件改变为比原来还要小的尺寸,那么就根本不会产生任何绘制事件。


setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);

原型:void setSizePolicy ( QSizePolicy::Policy horizontal, QSizePolicy::Policy vertical )

enum QSizePolicy::Policy

This enum describes the various per-dimension sizing types used when constructing a QSizePolicy.

ConstantValueDescription
QSizePolicy::Fixed0The QWidget::sizeHint() is the only acceptable alternative, so the widget can never grow or shrink (e.g. the vertical direction of a push button).
QSizePolicy::MinimumGrowFlagThe sizeHint() is minimal, and sufficient. The widget can be expanded, but there is no advantage to it being larger (e.g. the horizontal direction of a push button). It cannot be smaller than the size provided by sizeHint().
QSizePolicy::MaximumShrinkFlagThe sizeHint() is a maximum. The widget can be shrunk any amount without detriment if other widgets need the space (e.g. a separator line). It cannot be larger than the size provided by sizeHint().
QSizePolicy::PreferredGrowFlag | ShrinkFlagThe sizeHint() is best, but the widget can be shrunk and still be useful. The widget can be expanded, but there is no advantage to it being larger than sizeHint() (the default QWidget policy).
QSizePolicy::ExpandingGrowFlag | ShrinkFlag | ExpandFlagThe sizeHint() is a sensible size, but the widget can be shrunk and still be useful. The widget can make use of extra space, so it should get as much space as possible (e.g. the horizontal direction of a horizontal slider).
QSizePolicy::MinimumExpandingGrowFlag | ExpandFlagThe sizeHint() is minimal, and sufficient. The widget can make use of extra space, so it should get as much space as possible (e.g. the horizontal direction of a horizontal slider).
QSizePolicy::IgnoredShrinkFlag | GrowFlag | IgnoreFlagThe sizeHint() is ignored. The widget will get as much space as possible.

Qt颜色的设置,下面列出了QT里面的颜色


image = QImage(32, 16, QImage::Format_ARGB32);
好吧、先让我们看看原型:

QImage::QImage ( int width, int height, Format format )

关于Format的定义:
QImage::Format_ARGB325The image is stored using a 32-bit ARGB format (0xAARRGGBB).
设置为32位的ARGB格式。

其他实现部分见下一章。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值