Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. I dont understand the layout mechanism :( (i came from WPF)

I dont understand the layout mechanism :( (i came from WPF)

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 482 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Boris1980
    wrote on last edited by
    #1

    Hello guys,

    i have an custom widget, this contains a QLabel as headline , and the rest of the widget space shoud used by a QListWidget.

    my code:

    QVBoxLayout *root = new QVBoxLayout(this);
    	root->setSizeConstraint(QLayout::SetMinimumSize); /* mybay be this */
    	setLayout(root);
    
    	_headLine = new QLabel("HeadLine", this);
    	_headLine->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); /* or maybe that */
    	root->addWidget(_headLine, Qt::AlignTop); /* and align top? */
    
    	_alarmListView = new QListWidget(this);
    	_alarmListView->setItemDelegate(new ItemDelegate(_alarmListView));
    	root->addWidget(_alarmListView);
    

    but both elems in my layout takes the same space 50/50 ! But i want, that the head line (QLabel) only takes its neede height, an the rest for the QListWidget.
    Do i need a another layout?

    For example , in WPF i can take a Dockpanel, and dock the Label to the top, and the reset space is uses by the list control. But in QT it seem must more complicated... to layout :(

    can

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      quick solution: just don't overdo it:

      	QVBoxLayout *root = new QVBoxLayout(this);
      	_headLine = new QLabel("HeadLine", this);
      	root->addWidget(_headLine);
      	_alarmListView = new QListWidget(this);
      	_alarmListView->setItemDelegate(new ItemDelegate(_alarmListView));
      	root->addWidget(_alarmListView);
      

      Explanation:
      QSizePolicy::Minimum does not do what you think it does:

      from https://doc.qt.io/qt-5/qsizepolicy.html#Policy-enum

      The sizeHint() is minimal, and sufficient. The widget can be expanded, but there is no advantage to it being larger (e.g. the horizontal direction of a push button). It cannot be smaller than the size provided by sizeHint().

      What you want is QSizePolicy::Maximum but, again, you don't need to do anything, the default already does what you want

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      5
      • B Offline
        B Offline
        Boris1980
        wrote on last edited by
        #3

        Oh thank;) it works.. but when i add "Qt::AlignTop" , does a 50/50 allignment.. thats confusing :(

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved