Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to add a label on a layout that covers the entire window.



  • Hello,
    I am trying to create a sliding window for my main login page i.e i have created a simple login page with a layout and i want to add a label on top of the login page which will cover the login page . It is more like a welcome page . The welcome page will slide up and the login page will be seen.

    So i have placed all the widgets on the central widget for the login page using a layout.
    Now the problem is when i try to add a label that covers the entire window, the layout wont let me do that , also if i set the size policy to fix and change the size , it changes the size of the entire window. Is there a way i can add the label on the layout but without affecting the present layout . I tried MainWindow :: setCentralWidget() , but that stops me from doing the sliding animation.

    Also if anybody know any other easy way by which i can achieve what i'm trying to do , please tell me.
    I Just want a simple welcome page that slides up on clicking a button.
    Thank youqrt


  • Lifetime Qt Champion

    Hi,

    One way could be to position/resize your label by hand over the central widget.



  • But the layout doesnt let me do that.


  • Lifetime Qt Champion

    @ronyNS Don't use the layout for this label. Add it to the widget (not to the layout) and position/resize it as needed.



  • @jsulm How to add to a widget. Sorry im a beginner. The addwidget() function can be only used with a layout so if you are telling me to add without a layout i cannot use that function. If i drag the label on the ui it moves all the widgets. I cant find a way to add the entire label on top of the layout.


  • Lifetime Qt Champion

    @ronyNS Just pass the central widget as parent to the constructor


  • Lifetime Qt Champion

    What @jsulm and I are suggesting is that you don't put that label in any layout. Handle it by hand both for size and position.



  • I understand what you are trying to say. But i dont know how to do that. Should i use setGeometry() or something else. How should i resize it.


  • Lifetime Qt Champion

    Reimplement the resizeEvent of your main widget and resize your label in there.