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. Settings margins within a QStackedWidget
Forum Updated to NodeBB v4.3 + New Features

Settings margins within a QStackedWidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 1.4k Views 1 Watching
  • 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.
  • S Offline
    S Offline
    Smeeth
    wrote on last edited by
    #1

    I am coding an application that includes a dialog for entering a person's information. These entries are mostly text entries, so I am using QLineEdit() s.

    I would like to put the QLineEdits in a QStackedWidget so that alternative input methods can be used (for instance, entering Height in cm requires 1 text box, but entering Height as Ft and Inches requires 2). When I add the QLineEdit to a QStackedWidget and add the QStackedWidget to the form, the QLineEdits are expanded to fill the space inside the layout.

    Here is the dialog with no QStackedWidgets, just the QLineEdit objects added to the main layout. As you can see everything is spaced properly and evenly.
    0_1551804394364_ec68e764-027d-4101-8d76-11b3377f65eb-image.png

    Here is the dialog with the Height and Weight QLineEdit objects inside QStackedWidgets. The Height and Weight QLineEdit objects are expanded to fill the layout.
    0_1551804530215_bb01fbb4-a561-4de3-967f-94c873a5b9af-image.png

    Here is my code for creating the Weight QStackedWidget, for example:

    weightEntry = new QStackedWidget; 
    weightKgTxt = new QLineEdit();
    weightLbTxt = new QLineEdit();
    weightEntry->addWidget(weightKgTxt);
    weightEntry->addWidget(weightLbTxt)
    

    I have tried using the setSizePolicy() method of QStackedWidget but I get an error :

    weightEntry->setSizePolicy(QSizePolicy::Minimum);
    
    error: calling private constructor of class QSizePolicy
    

    How can I change the layout or format of QStackedWidget so the QLineEdits inside will be evenly spaced from everything else, like my first picture?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      One thing you can do since you only have line edits in your stacked widget is to use something like:

      `weightEntry.setMaximumHeight(weightKgTxt->sizeHint().height());

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      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