简体   繁体   中英

Alignment in a GridLayout in PyQt4

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

具有Alignment类的Qt模块位于PyQt4.QtCore.Qt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM