[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] Alignment Issue in QStatusbar
From:       Tong Zhang <warriorlance () gmail ! com>
Date:       2019-05-18 2:13:00
Message-ID: CABUYRu6ej1Qkb6V4dNjxZeg6L6SBNqCV+FbNJsN0xeR=SJd_jw () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


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@gmail.com>
wrote:

> Il giorno ven 17 mag 2019 alle ore 04:25 Tong Zhang <
> warriorlance@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
>

[Attachment #5 (text/html)]

<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Thanks, Maurizio. I&#39;m \
running with Linux, everything is fine now, what I was missing is <span \
style="font-family:courier new,monospace">Qt.AlignVCenter</span>, after I changing to \
<span style="font-family:courier new,monospace">lbl.setAlignment(Qt.AlignLeft | \
Qt.AlignVCenter)<span style="font-family:arial,sans-serif">, it looks \
perfect.</span><br></span></div><div><span style="font-family:arial,sans-serif">Here \
is the functional minimal testing script:</span></div><div><span \
style="font-family:courier new,monospace">from PyQt5.QtWidgets import \
QMainWindow<br>from PyQt5.QtWidgets import QToolButton<br>from PyQt5.QtWidgets import \
QStatusBar<br>from PyQt5.QtWidgets import QLabel<br>from PyQt5.QtCore import \
Qt<br><br><br>class MyWindow(QMainWindow):<br>       def __init__(self, parent=None, \
**kws):<br>               QMainWindow.__init__(self, parent)<br>               \
self.setParent(parent)<br><br>               sb = QStatusBar(self)<br>               \
lbl = QLabel(&quot;My App (Version: 1.0)&quot;)<br>               \
lbl.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)<br>               btn = \
QToolButton(self)<br>               sb.addPermanentWidget(btn, 0)<br>               \
sb.addPermanentWidget(lbl, 1)<br><br>               \
self.setStatusBar(sb)<br><br><br>if __name__ == &quot;__main__&quot;:<br>       from \
PyQt5.QtWidgets import QApplication<br>       import sys<br><br>       app = \
QApplication(sys.argv)<br>       m = MyWindow()<br>       m.show()<br><br>       \
sys.exit(app.exec_())<br><br></span></div></div></div><div>- \
Tong<br></div><div><br></div><div class="gmail_quote"><div dir="ltr" \
class="gmail_attr">On Fri, May 17, 2019 at 5:20 PM Maurizio Berti &lt;<a \
href="mailto:maurizio.berti@gmail.com">maurizio.berti@gmail.com</a>&gt; \
wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div \
dir="ltr"></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Il giorno \
ven 17 mag 2019 alle ore 04:25 Tong Zhang &lt;<a href="mailto:warriorlance@gmail.com" \
target="_blank">warriorlance@gmail.com</a>&gt; ha scritto:<br></div><blockquote \
class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid \
rgb(204,204,204);padding-left:1ex"><div \
dir="ltr"><div>Hello,</div><div><br></div><div>I&#39;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!<br></div></div></blockquote><div><br></div><div></div></div><div>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 &quot;reduce&quot; the code for the example, you \
often find what actually is wrong by yourself); it&#39;s also better to specify the \
environment you are running from (Operating System, Python and Qt \
versions).</div><div><br>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.</div><div><br></div><div>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).</div><div><br></div><div>Cheers,</div><div>Maurizio</div><div><br></div>-- \
<br><div dir="ltr" class="gmail-m_-1012761596910096604gmail_signature">È difficile \
avere una convinzione precisa quando si parla delle ragioni del cuore. - \
&quot;Sostiene Pereira&quot;, Antonio Tabucchi<br><a href="http://www.jidesk.net" \
target="_blank">http://www.jidesk.net</a></div></div> </blockquote></div></div>


[Attachment #6 (text/plain)]

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic