qtqlabelqframe

QLabel border visible within QGridLayout


I'm facing a problem with UI design.

I'm using QT 4.6.2 with QTCreator 1.3.1

I have a QFrame with a background image that "draw" the grid see image below

When i add a QLabel within the layout, when i run the app i see top left border. For test, i moved out the QLabel from the Layout and it works as expected (no border at all)

Do you have any idea about that?

Thanks in advance for your kindly help

Leo


Solution

  • You are probably using a style sheet to set the background of your QFrame. Something like this:

    QFrame{
        background-image: url(picture.png);
    }
    

    Style sheet propagates to children widgets, so my idea is that your background is applied to the children QLabels as well.

    Change your style sheet to this one (notice the dot at the beginning):

    .QFrame{
        background-image: url(picture.png);
    }
    

    The dot selector will restrict the style sheet only to the children widgets of your QFrame that are of type QFrame, but won't apply it to inheriting classes like QLabel. See the docs to learn more about selectors.