【问题标题】:How can I tile two pixmaps in PyQt 4?如何在 PyQt 4 中平铺两个像素图?
【发布时间】:2011-04-07 19:50:32
【问题描述】:

从磁盘上的 2 个具有相同尺寸的 png 文件(我可以加载到 2 个像素图)开始,我如何将它们水平平铺并在它们之间留一个小的垂直(透明)空间,如下所示:

aaaaa bbbbb
aaaaa bbbbb
aaaaa bbbbb

并将结果另存为另一个像素图?

环境:Windows 上的 PyQt 4.8.3

【问题讨论】:

    标签: python windows qt qt4 pyqt4


    【解决方案1】:

    这应该是一个很好的起点(未经测试):

    painter = QPainter() // the QPainter to the object you want to paint
    
    a = QImage("file1.png")
    b = QImage("file2.png")
    space = 5 // pixels
    tile = QPixmap(QSize(a.width() + b.width(), a.height() + space)
    painter2.setBrush(QBrush(QColor(0, 0, 0, 0)))
    painter2.fillRect(0, 0, tile.width(), tile.height())
    painter2 = QPainter(tile)
    painter2.drawImage(QPoint(0, 0), a)
    painter2.drawImage(QPoint(a.width(), 0), b)
    
    painter.setBrush(tile.toImage())
    
    // now anything you draw will be filled with the tiled pattern
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-24
      相关资源
      最近更新 更多