Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

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

    General and Desktop
    2
    5
    6155
    Loading More Posts
    • 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.
    • xiazeyi
      xiazeyi last edited by

      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 Reply Quote 0
      • Chris Kawa
        Chris Kawa Moderators last edited by

        @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 Reply Quote 0
        • xiazeyi
          xiazeyi last edited by

          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 Reply Quote 0
          • Chris Kawa
            Chris Kawa Moderators last edited by

            How do you change the size of the children frames?

            1 Reply Last reply Reply Quote 0
            • xiazeyi
              xiazeyi last edited by

              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 Reply Quote 0
              • First post
                Last post