[PyQt] Alignment Issue in QStatusbar

Tong Zhang warriorlance at gmail.com
Sat May 18 03:13:00 BST 2019


Thanks, Maurizio. I'm running with Linux, everything is fine now, what I
was missing is Qt.AlignVCenter, after I changing to
lbl.setAlignment(Qt.AlignLeft
| Qt.AlignVCenter), it looks perfect.
Here is the functional minimal testing script:
from PyQt5.QtWidgets import QMainWindow
from PyQt5.QtWidgets import QToolButton
from PyQt5.QtWidgets import QStatusBar
from PyQt5.QtWidgets import QLabel
from PyQt5.QtCore import Qt


class MyWindow(QMainWindow):
    def __init__(self, parent=None, **kws):
        QMainWindow.__init__(self, parent)
        self.setParent(parent)

        sb = QStatusBar(self)
        lbl = QLabel("My App (Version: 1.0)")
        lbl.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
        btn = QToolButton(self)
        sb.addPermanentWidget(btn, 0)
        sb.addPermanentWidget(lbl, 1)

        self.setStatusBar(sb)


if __name__ == "__main__":
    from PyQt5.QtWidgets import QApplication
    import sys

    app = QApplication(sys.argv)
    m = MyWindow()
    m.show()

    sys.exit(app.exec_())

- Tong

On Fri, May 17, 2019 at 5:20 PM Maurizio Berti <maurizio.berti at gmail.com>
wrote:

> Il giorno ven 17 mag 2019 alle ore 04:25 Tong Zhang <
> warriorlance at gmail.com> ha scritto:
>
>> Hello,
>>
>> I'm trying to create add widgets into QStatusbar, as the attached
>> screenshot shows, the first widget, which is a qtoolbutton and the second
>> widget, which is a qlabel, is not aligned well. I want them vertically
>> center aligned,  could somebody give me some hint? Thanks very much!
>>
>
> From your code everything seems fine, but you should provide a minimal,
> correct and reproducible example to better understand what might be going
> on (my experience shows that what usually happens is that, once you
> "reduce" the code for the example, you often find what actually is wrong by
> yourself); it's also better to specify the environment you are running from
> (Operating System, Python and Qt versions).
>
> I tested it on Linux and Windows (through wine, though). From the look of
> the attached screenshot it seems you might be running on Windows 10, and
> unfortunately I cannot accurately test on that platform.
>
> It could be a bug, but also it might depend on what you did with the
> QStatusBar and the QToolButton (I can see an icon and a menu set, but maybe
> you changed something else too).
>
> Cheers,
> Maurizio
>
> --
> È difficile avere una convinzione precisa quando si parla delle ragioni
> del cuore. - "Sostiene Pereira", Antonio Tabucchi
> http://www.jidesk.net
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20190517/16918252/attachment-0001.html>


More information about the PyQt mailing list