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. Creating a widget...

Creating a widget...

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 263 Views 2 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by
    #1

    I am trying to create a widget that will contain a QPushButton and a QLineEdit, the push button will contain just ... and will invoke the Qt file selection dialog, the QLineEdit will display the selection.

    So far I have:

    QWidget* pFSContr = new QWidget();
    QGridLayout* pgrdFSLayout = new QGridLayout();
    QPushButton* pbtnBrowse = new QPushButton();
    QLineEdit* plnedFS = new QLineEdit();
    pFSContr->setLayout(pgrdFSLayout);
    pFSContr->setMininumSize(0, 0);
    QRect rctGeom(pbtnBrowse->geometry());
    rctGeom.setWidth(24);
    rctGeom.setHeight(24);
    pbtnBrowse->setGeometry(rctGeom);
    pgrdFSLayout->addWidget(pbtnBrowse, 0, 0, 1, 1, Qt::AlignLeft);
    pgrdFSLayout->addWidget(plnedFS, 0, 1, 1, 1, Qt::AlignLeft);
    

    Is there a layout or setting that will allow me to set the size of the contained widgets as presently any size's set are ignored ?

    Kind Regards,
    Sy

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #2

      Setting a geometry on a widget that is governed by a layout has no effect, as it's the layout's actual job to set that geometry. You can, however, manage the minimum and maximum size of the widget that the layout will respect. To hardcode a constant size of a widget you can set its minimum and maximum size to the same value. There's also a shortcut function that lets you do both in one go: setFixedSize.

      Keep in mind though, that fixing a widget's size is not a good idea, especially if it contains any sort of text (even if it's just ...). Different users will have different screens with different DPI and scaling settings and whatever looks good on your monitor might become too small or have the text not fit inside the widget on another screen with different scaling. A far more robust approach is to manage size policies and stretch factors, which deal in a more abstract or proportion based units that will scale properly on different displays.

      Also - passing the alignment parameter to addWidget is probably not what you actually mean here. This parameter is for cases when all widgets in layout have maximum sizes that sum to less than the parent widget's size. In that case the alignment is used to position such widget within layout grid's cell. In your case you've got an expanding line edit, which means the widgets will occupy entire available space in the layout so setting alignment has no use. I'd leave that parameter at its default value.

      1 Reply Last reply
      4

      • Login

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