Skip to content
Advertisement

How to align two widgets more closely in PyQt5 layouts?

How to align two widgets more closely? In my code, I want to align QLabel 1 and QLabel 2 more closely (i.e. QLabel 2 aligned just below the QLabel 1, with minimum spacing).

JavaScript

Advertisement

Answer

I assume what you’re trying to achieve is a double underline for the text in the first label. The problem with your example is that the unicode character (U+2550) is centered vertically, so there will always be some fixed space above it. The unicode box-drawing characters don’t include a top-aligned double-underline, so a different approach is needed.

One solution is to use html/css inside the label to draw a double border below the text. This has to be done using a table-cell, because Qt only supports a limited subset of html/css:

JavaScript

enter image description here

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement