質問

I'm trying to create a QGridLayout in PyQt4, and I can't figure out for the life of me how to change the alignment of the contents of the cells. The docs say that any nonzero value for the 5th (6th counting self) argument means that the element being added doesn't fill the grid space, but so far I've not found any value that doesn't throw an error. The Docs say to use a Qt.Alignment object, but I can't find the Qt module, and there's nothing of that nature in PyQt4.

Any suggestions?

When I try importing PyQt4.QtCore.Qt as suggested below, this is what happens:

#     import PyQt4.QtCore.Qt as Qt
# ImportError: No module named Qt #

is my install borked or something?

役に立ちましたか?

解決

import PyQt4.QtCore.Qt

Won't work, since that last Qt isn't a module (it's most likely just a class providing namespacing). Do the following:

from PyQt4 import QtCore

Then for, say, right alignment:

QtCore.Qt.AlignRight

This is what you should pass to the alignment argument of QGridLayout.addItem

他のヒント

The Qt module that has the class Alignment is at PyQt4.QtCore.Qt

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top