<div dir="ltr">I asked the following question on StackOverflow but didn't get an answer. Perhaps people here can help.<br><br><table><tbody><tr><td class=""> I have a simple task. 

<p>I want to right align richtext (HTML) in a PyQt QLabel. The QLabel works fine until I resize the widget making it 
*smaller* than the text length. At that point, the text to the right gets 
cut off. The QLabel works properly with plain text. <br></p>

<p>In the PyQt example below, I list numbers one to ten. I want to 
always see the number 'ten' even when I resize the widget. It works for 
plain text (labelPT) but breaks for richtext (labelRT). How can I get the labelRT version working properly?<br></p><p>Any help would be very welcome.</p><p>Laurence<br></p><pre style class=""><code><span class="">from</span><span class=""> </span><span class="">PyQt4</span><span class=""> </span><span class="">import</span><span class=""> </span><span class="">QtGui</span><span class="">,</span><span class=""> </span><span class="">QtCore</span><span class="">

</span><span class="">import</span><span class=""> sys

</span><span class="">if</span><span class=""> __name__ </span><span class="">==</span><span class=""> </span><span class="">'__main__'</span><span class="">:</span><span class="">
    app </span><span class="">=</span><span class=""> </span><span class="">QtGui</span><span class="">.</span><span class="">QApplication</span><span class="">(</span><span class="">sys</span><span class="">.</span><span class="">argv</span><span class="">)</span><span class="">
    mw </span><span class="">=</span><span class=""> </span><span class="">QtGui</span><span class="">.</span><span class="">QWidget</span><span class="">()</span><span class="">

    labelPT </span><span class="">=</span><span class=""> </span><span class="">QtGui</span><span class="">.</span><span class="">QLabel</span><span class="">()</span><span class="">
    labelPT</span><span class="">.</span><span class="">setText</span><span class="">(</span><span class="">'one two three four five six seven eight nine ten'</span><span class="">)</span><span class="">
    labelPT</span><span class="">.</span><span class="">setAlignment</span><span class="">(</span><span class="">QtCore</span><span class="">.</span><span class="">Qt</span><span class="">.</span><span class="">AlignRight</span><span class="">)</span><span class="">

    labelRT </span><span class="">=</span><span class=""> </span><span class="">QtGui</span><span class="">.</span><span class="">QLabel</span><span class="">()</span><span class="">
    labelRT</span><span class="">.</span><span class="">setText</span><span class="">(</span><span class="">'one two three four <b>five</b> six seven eight nine ten'</span><span class="">)</span><span class="">
    labelRT</span><span class="">.</span><span class="">setAlignment</span><span class="">(</span><span class="">QtCore</span><span class="">.</span><span class="">Qt</span><span class="">.</span><span class="">AlignRight</span><span class="">)</span><span class="">

    vbox </span><span class="">=</span><span class=""> </span><span class="">QtGui</span><span class="">.</span><span class="">QVBoxLayout</span><span class="">()</span><span class="">
    vbox</span><span class="">.</span><span class="">addWidget</span><span class="">(</span><span class="">labelPT</span><span class="">)</span><span class="">
    vbox</span><span class="">.</span><span class="">addWidget</span><span class="">(</span><span class="">labelRT</span><span class="">)</span><span class="">

    mw</span><span class="">.</span><span class="">setLayout</span><span class="">(</span><span class="">vbox</span><span class="">)</span><span class="">
    mw</span><span class="">.</span><span class="">setMinimumWidth</span><span class="">(</span><span class="">30</span><span class="">)</span><span class="">
    mw</span><span class="">.</span><span class="">show</span><span class="">()</span><span class="">

    sys</span><span class="">.</span><span class="">exit</span><span class="">(</span><span class="">app</span><span class="">.</span><span class="">exec_</span><span class="">())<br><br><br></span></code></pre></td><td class="">

<br></td></tr></tbody></table></div>