Results 1 to 7 of 7

Thread: QLabel or any Widget Resize Itself, how to disable.

  1. #1
    Join Date
    Mar 2014
    Posts
    27
    Thanks
    9
    Qt products
    Qt5
    Platforms
    Windows

    Default QLabel or any Widget Resize Itself, how to disable.

    Hi, I have a problem that is so annoying. Already searched so many post but still don't figure out how to solve.

    I have a QLabel in a QMainWindow, the problem is that everytime I add this Label to the window (using setCentralWidget),
    the QLabel takes the whole unused space of the window. The QLabel Resize itself and takes the whole space.

    I tried to use setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixe d); but didnt work.

    By the way, there is other question, can I add as many Labels, buttons in a Container without using layouts?
    something like, Table(Draughts), and the table can be the container of anything? I mean setting specific positions without having my first problem? (The Resize issue).

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QLabel or any Widget Resize Itself, how to disable.

    The central widget of a QMainWindow always occupies all the available space inside the main window. If you want to decouple the size of the label from the size of the main window then you need to place it in a container with a suitable layout and spacers or other widget to occupy the "empty" space. Then set that container as the central widget.

    By the way, there is other question, can I add as many Labels, buttons in a Container without using layouts?
    Yes. Make the labels, buttons, etc. children of the container widget and they will appear inside and on top of the container.. You will need to position, size and resize them manually.

    IMHO, if you think you need to manually place large numbers of widgets then you are almost certainly thinking about your problem the wrong way.

  3. #3
    Join Date
    Mar 2014
    Posts
    27
    Thanks
    9
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QLabel or any Widget Resize Itself, how to disable.

    The container have an specific data type or is just a QWidget called container?
    Can you show me example? sorry I'm so new on this.

    label = new QLabel("Test");
    label->setMinimumSize(60,60);
    container = new QWidget(label);
    setCentralWidget(container);

    Its this ok?
    And thanks.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QLabel or any Widget Resize Itself, how to disable.

    Container can be any widget, but usually it is just a QWidget, a QFrame or a QGroupBox.
    In your case a QWidget is sufficient.

    Your code looks right for an unlayouted window.
    Usually you don't want that at all, manual layouting is tedious.

    Cheers,
    _

  5. #5
    Join Date
    Mar 2014
    Posts
    27
    Thanks
    9
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QLabel or any Widget Resize Itself, how to disable.

    Quote Originally Posted by anda_skoa View Post
    Container can be any widget, but usually it is just a QWidget, a QFrame or a QGroupBox.
    In your case a QWidget is sufficient.

    Your code looks right for an unlayouted window.
    Usually you don't want that at all, manual layouting is tedious.

    Cheers,
    _
    Thanks but, this doesn't show my QLabel on the window. And there's a method to add the QLabel without sending throw the constructor of the QWidget?

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QLabel or any Widget Resize Itself, how to disable.

    The widget "container" should be the parent of "label", not the other way around.
    "We can't solve problems by using the same kind of thinking we used when we created them." -- Einstein
    If you are posting code then please use [code] [/code] tags around it - makes addressing the problem easier.

  7. The following user says thank you to ChrisW67 for this useful post:

    vitaR (30th June 2014)

  8. #7
    Join Date
    Mar 2014
    Posts
    27
    Thanks
    9
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QLabel or any Widget Resize Itself, how to disable.

    Thanks everyone for your answers. I like this forum

Similar Threads

  1. How to disable resize in a QWidget
    By aguleo in forum Newbie
    Replies: 2
    Last Post: 17th February 2013, 21:58
  2. Replies: 0
    Last Post: 27th September 2011, 00:14
  3. Disable resize events
    By myrky in forum Qt Programming
    Replies: 7
    Last Post: 26th June 2009, 13:49
  4. Auto resize QLabel
    By munna in forum Newbie
    Replies: 12
    Last Post: 6th August 2008, 14:39
  5. Double click resize window disable
    By MarkoSan in forum Qt Programming
    Replies: 3
    Last Post: 13th May 2008, 12:35

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.