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. Using min-width or min-height in QSS allows cropping any QWidget contents
Forum Updated to NodeBB v4.3 + New Features

Using min-width or min-height in QSS allows cropping any QWidget contents

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 2.3k 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.
  • napajejenunedk0N Offline
    napajejenunedk0N Offline
    napajejenunedk0
    wrote on last edited by napajejenunedk0
    #1

    Setting either min-width or min-height in QSS for any QWidget-derived UI control results in the ability to crop its contents in horizontal or vertical direction respectively upon downsizing it interactively. It is as if the QSS code is discarding the UI control's size hint whereas it should just add an additional restriction that the size shouldn't be smaller in either of the directions. Simplest case:

    int main( int argc, char* argv[] )
    {
        QApplication a( argc, argv );
    
        QWidget w;
        QHBoxLayout* const layout = new QHBoxLayout( & w );
        QPushButton* const pb = new QPushButton( "0 1234567890 1 1234567890 2 1234567890" );
        pb->setStyleSheet( "min-width: 10px;" );
        layout->addWidget( pb );
    
        w.show();
    
        return a.exec();
    }
    

    After running the code, squeeze the window horizontally and see that the button's text would get cropped where if the QSS was missing no such thing would happen. The same happens when using C++ code for the same purpose:
    pb->setMinimumWidth( 10 );

    Q: Is there a way to prevent a given QWidget from being squeezed below its size hint aside from:
    pb->setSizePolicy( QSizePolicy::Minimum, pb->sizePolicy().verticalPolicy() );

    which fails to work. Currently, the QPushButton is put inside a hollow QWidget because otherwise the former could be squeezed horizontally even without setting a minimum width.

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

      Hi,

      It works on macOS with Qt 5.12.

      Just one thing, "10px" is not really wide for a button. What output are you expecting ?

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

      napajejenunedk0N 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        It works on macOS with Qt 5.12.

        Just one thing, "10px" is not really wide for a button. What output are you expecting ?

        napajejenunedk0N Offline
        napajejenunedk0N Offline
        napajejenunedk0
        wrote on last edited by
        #3

        @SGaist I've already written my expectations about how it should behave above:

        It is as if the QSS code is discarding the UI control's size hint whereas it should just add an additional restriction that the size shouldn't be smaller in either of the directions.

        And from your first sentence it appears that you have understood it:

        It works on macOS with Qt 5.12.

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

          What I meant was: what are you expecting from a 10px wide button ?

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

          napajejenunedk0N 1 Reply Last reply
          0
          • SGaistS SGaist

            What I meant was: what are you expecting from a 10px wide button ?

            napajejenunedk0N Offline
            napajejenunedk0N Offline
            napajejenunedk0
            wrote on last edited by napajejenunedk0
            #5

            @SGaist I wasn't expecting it to be squeezable below its size hint. I expected that the explicitly specified minimum width wouldn't be taken into consideration due to being lower than the size hint.

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

              As the name suggests size hint is a hint and only that. If you want boundaries, then it's the role of the min/max size/width/height methods.

              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