can explain that the function arguments should take

setalignment= none, qt_alignmentflag= none):

in advance Thank you.

For what type?

user2072002021-04-09 07:12:12
  • Answer # 1

    Let's look at the method description Pyqt5 :

    # Real Signature Unknown; Restored from __doc__
    def setalignment (Self, Union, QT_ALIGNMENT= NONE, QT_ALIGNMENTFLAG= NONE):
        "" "SETATIGNMENT (SELF, UNION [QT.ALIGNMENT, QT.alignmentFlag])" ""

    It shows that the real signature described in __doc__ has one parameter (this is confirmed when trying to transfer more than one parameter to the function), which either Qt.alignment either Qt.alignmentFlag .

    therefore, parameters Union, QT_ALIGNMENT= NONE, QT_ALIGNMENTFLAG= NONE In fact, this is one parameter.

    Additional confirmation can be seen if you see Description of the same method in the documentation of Qt itself:

    Void SetAlignment (Qt :: Alignment)

    And then the question may arise:

    why in pyqt5 this parameter is described as Union [Qt.alignment, Qt.alignmentFlag], and in the original documentation just Qt :: Alignment?

    To answer the question, you also need to look at the Qt documentation for the listing Qt :: Alignment:

    Enum Qt :: AlignmentFlag
    Qt :: Alignment

    Qt :: Alignment This is a set of flags Qt :: AlignmentFlag : Qt :: Alignleft. . Qt :: alignright etc., in other words in Qt :: Alignment can transmit a specific flag or several minutes at once: for example, the flag Qt :: Aligncenter. Built from flags Qt :: AlignVcenter. and Qt :: Alignhcenter. .

    To make a list of flags need to be listed through a bit or -Operator | :

    My_align_Center= Qt :: AlignVCenter | Qt :: Alignhcenter.

    a Union [Qt.alignment, Qt.alignmentFlag] This is an indication of one of the listed variations in the parameter, which converges with the fact that he wrote above.

    I explained why it is indicated Union [Qt.alignment, Qt.alignmentFlag] in the description of the parameter SetAlignMent. .

    Now, a little practice.

    below use Alignment :

    from pyqt5.Qtwidgets import QLabel, Qapplication, QGridlayout, QWidget
    from pyqt5.Qtcore Import Qt
        Label= QLabel ('Test')
        label.setfixedsize (40, 40)
        label.setframestyle (QLabel.Box)
        label.setAlignment (Alignment)
        Return Label
    App= Qapplication ([])
    layout= qgridlayout ()
    layout.addwidget (Create_Label (Qt.alignleft), 0, 0)
    layout.addwidget (Create_Label (Qt.alignleft | Qt.alignBottom), 0, 1)
    layout.addwidget (Create_Label (Qt.alignleft | Qt.alignVCenter), 0, 2)
    layout.addwidget (Create_Label (Qt.alignleft | Qt.aligntop), 0, 3)
    layout.addwidget (Create_Label (Qt.alignhCenter | Qt.aligntop), 0, 4)
    layout.addwidget (Create_Label (Qt.alignRight | Qt.alignVCenter), 0, 5)
    w= qwidget ()
    W.Setlayout (Layout)
    w.show ()
    app.exec ()


    Can you please tell once again what the difference between AlignmentFlag and Alignment

    Gleb2021-04-09 07:12:12

    AlignmentFlag is a specific flag, such as Left. ALIGNMENT -set of flags from one and more

    gil9red2021-04-09 07:12:12