0
在Qt中,我有一個5px寬度和4px高度的Qpixmap,我用寬度爲.08和高度爲.08的矩形填充它,但形成的矩形不相等尺寸如我所給`。 我想提請相等尺寸Qpainter的drawRect函數不給等維矩形
QLabel *a=new QLabel();
QPixmap b(5,4);
a->setFixedSize(b.size());
QPainter painter(&b);
heightOfCheckeredBox=.08;
widthOfCheckeredBox=.08;
bool switchBetweenBlackAndWhiteBoxRowDirection=true;
int switchBetweenBlackAndWhiteBoxColumnDirection=0;
for(qreal i=0;i<4;i+=heightOfCheckeredBox)
{
for(qreal j=0;j<5;j+=widthOfCheckeredBox)
{
if(switchBetweenBlackAndWhiteBoxRowDirection)
{
painter.setPen(Qt::white);
painter.setBrush(Qt::white);
switchBetweenBlackAndWhiteBoxRowDirection=false;
}
else
{
painter.setPen(Qt::gray);
painter.setBrush(Qt::gray);
switchBetweenBlackAndWhiteBoxRowDirection=true;
}
QRectF rectangle(j,i,widthOfCheckeredBox,heightOfCheckeredBox);
painter.drawRect(rectangle);
}
switchBetweenBlackAndWhiteBoxColumnDirection++;
if(int(switchBetweenBlackAndWhiteBoxColumnDirection)%2==0)
switchBetweenBlackAndWhiteBoxRowDirection=true;
else
switchBetweenBlackAndWhiteBoxRowDirection=false;
}
a->setPixmap(b);
a->show();
問自己意味着什麼繪製一個矩形,其寬度和高度的像素的100分之8。你期望底層渲染算法能做什麼? –
以可以使用整個(或幾乎整個)像素的比例繪製它,然後使用已知算法將其縮小。 – phyatt
我有一個圖像,我需要在它的背景中有另一個圖像,這是我的方格圖像,我正在用白色和黑色方塊現在爲不同的圖像,我需要在每種情況下,在視圖中 –