Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 529
HunnyBear Avatar asked Dec 13 '22 07:12

HunnyBear


1 Answers

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

like image 55
Eli Bendersky Avatar answered Dec 22 '22 05:12

Eli Bendersky