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. Setting min-width/max-width in stylesheet (.qss) does not work after setting layout size constraint of QDialog to QLayout::SetFixedSize

Setting min-width/max-width in stylesheet (.qss) does not work after setting layout size constraint of QDialog to QLayout::SetFixedSize

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 7.5k 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.
  • xiazeyiX Offline
    xiazeyiX Offline
    xiazeyi
    wrote on last edited by
    #1

    Two requirements for dialog:

    1. Want the dialog can resize to suitable size when any child widget changes size, so I set layout size constraint of dialog to QLayout::SetFixedSize.
    2. Want the width of the dialog can be customized by min-width/max-width to fixed value in stylesheet.

    Issue:
    min-width/max-width in stylesheet (.qss) does not work.

    Here is the code:

    #include <qlayout.h>
    
    MyDialog::MyDialog(QWidget *parent) :
        QDialog(parent),
        ui(new Ui::MyDialog)
    {
        ui->setupUi(this);
        layout()->setSizeConstraint(QLayout::SetFixedSize);
        setStyleSheet("QDialog { min-width: 800px; max-width: 800px }"); // just a simple example, actually I want to customize in .qss file.
    }
    

    Questions:

    1. Is it correct behavior that width can not be customized after setting size constraint to QLayout::SetFixedSize?
    2. How can I achieve the requirements?
    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @xiazeyi said:

      Want the dialog can resize to suitable size when any child widget changes size, so I set layout size constraint of dialog to QLayout::SetFixedSize.

      SetFixedSize sets, well, a fixed size. It means it is set to the size hint value and can't be changed anymore by anything. So in your case this is definitely not what you want.

      Leave the size constraint at default and just specify the min and max values in the stylesheet.

      1 Reply Last reply
      0
      • xiazeyiX Offline
        xiazeyiX Offline
        xiazeyi
        wrote on last edited by
        #3

        My dialog has vertical layout and there are several QFrame widgets on the dialog, but the dialog won't resize to a smaller size when the height of its children becomes smaller.

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

          How do you change the size of the children frames?

          1 Reply Last reply
          0
          • xiazeyiX Offline
            xiazeyiX Offline
            xiazeyi
            wrote on last edited by
            #5

            By making some widgets in QFrame visible/invisible when the user does some interaction on dialog.
            Currently, I can set the direct children to fixed width instead of the dialog after setting size constraint of dialog to QLayout::SetFixedSize, then everything is ok.

            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