【问题标题】:PYQGIS Composer Label AlignmentPYQGIS Composer 标签对齐
【发布时间】:2017-01-12 17:30:11
【问题描述】:

我一直在为 QGIS 编写一些脚本,以便通过作曲家自动生成图集。

我遇到的唯一问题是我无法正确对齐作曲家标签。这是代码示例:

composerLabel = QgsComposerLabel(c)
newFont = QFont("times", 40)
composerLabel.setFont(newFont) 
composerLabel.setText("Hello world")
composerLabel.adjustSizeToText()
composerLabel.setItemPosition(c.paperWidth() / 2,0)

composerLabel.setHAlign(Qt.AlignCenter)

c.addItem(composerLabel)

Here's what the image output looks like

我查看了 API 并浏览了 PYQGIS 论坛,但没有其他人听起来像他们有类似的对齐问题。谁能看出我哪里出错了?

【问题讨论】:

    标签: alignment label pyqt4 qgis atlas


    【解决方案1】:

    您只需在setItemPosition 方法中添加ItemPositionMode

    # add label
    composerLabel = QgsComposerLabel(c)
    newFont = QFont("times", 40)
    composerLabel.setFont(newFont) 
    composerLabel.setText("Hello world")
    composerLabel.adjustSizeToText()
    composerLabel.setItemPosition(c.paperWidth() / 2,0,QgsComposerItem.UpperMiddle)
    
    composerLabel.setHAlign(Qt.AlignCenter)
    
    c.addComposerLabel(composerLabel)
    

    【讨论】:

    • 太棒了!是的,这解决了这个问题。谢谢弗朗西斯科! =)
    猜你喜欢
    • 2012-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-02
    • 2018-10-02
    • 2012-08-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多