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. Qt CSS Widget positioning and sizing
Forum Updated to NodeBB v4.3 + New Features

Qt CSS Widget positioning and sizing

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

    Is it possible to position and set the size of a widget using CSS ?

    I tried:

        QFrame {background-color: #e9efef;
    	    background-image: url('meshtile_4x4.png');
    	    border: 2px solid #cccccc;
                border-top-left-radius: 8px;
    	    border-top-right-radius: 8px;
    	    border-bottom-left-radius: 8px;
    	    border-bottom-right-radius: 8px;
                width:80%;}
    

    This didn't work, I was expecting the width to be 80% of the parent container, it wasn't.

    Kind Regards,
    Sy

    JonBJ 1 Reply Last reply
    0
    • SPlattenS SPlatten

      Is it possible to position and set the size of a widget using CSS ?

      I tried:

          QFrame {background-color: #e9efef;
      	    background-image: url('meshtile_4x4.png');
      	    border: 2px solid #cccccc;
                  border-top-left-radius: 8px;
      	    border-top-right-radius: 8px;
      	    border-bottom-left-radius: 8px;
      	    border-bottom-right-radius: 8px;
                  width:80%;}
      

      This didn't work, I was expecting the width to be 80% of the parent container, it wasn't.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @SPlatten
      In Qt QSS/CSS, all measurements such as width can only be expressed as a number ("measurement units", default pixels), there is no support for percentages :( https://doc.qt.io/qt-5/stylesheet-reference.html#length

      1 Reply Last reply
      1
      • SPlattenS Offline
        SPlattenS Offline
        SPlatten
        wrote on last edited by
        #3

        Thank you, shame, since CSS is a standard and the % are part of that standard, it shouldn't be difficult to incorporate.

        Kind Regards,
        Sy

        JonBJ 1 Reply Last reply
        0
        • SPlattenS SPlatten

          Thank you, shame, since CSS is a standard and the % are part of that standard, it shouldn't be difficult to incorporate.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @SPlatten
          QSS != CSS at all! And Qt widgets != HTML :) Basically you need to read through that reference page I quoted every time you want to put in some Qt stylesheet stuff; it something isn't there, it isn't supported. There are very good reasons why it would be difficult to incorporate....

          1 Reply Last reply
          0
          • SPlattenS Offline
            SPlattenS Offline
            SPlatten
            wrote on last edited by
            #5

            I really don't agree as I'm doing exactly this myself.

            Kind Regards,
            Sy

            JonBJ 1 Reply Last reply
            0
            • SPlattenS SPlatten

              I really don't agree as I'm doing exactly this myself.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @SPlatten
              Sorry, "don't agree" about what? That's how QSS is, I didn't write it.... If you wish to suggest to the Qt team that they add support for percentage measurements you can do so e.g. on the Qt bug system, but I assume since they haven't done so in many years they're not going to do it now.

              1 Reply Last reply
              0
              • SPlattenS Offline
                SPlattenS Offline
                SPlatten
                wrote on last edited by
                #7

                I haven't seen QSS mentioned before, I thought it was supposed to be CSS, thats why I said I don't agree.

                Kind Regards,
                Sy

                JonBJ 1 Reply Last reply
                0
                • SPlattenS SPlatten

                  I haven't seen QSS mentioned before, I thought it was supposed to be CSS, thats why I said I don't agree.

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #8

                  @SPlatten
                  https://doc.qt.io/Qt-5/stylesheet.html

                  The concepts, terminology, and syntax of Qt Style Sheets are heavily inspired by HTML Cascading Style Sheets (CSS) but adapted to the world of widgets.

                  The syntax is the same, but not the supported elements. The same with, say, QTextEdit support for "HTML", which is actually support for Qt's own "rich text" subset of HTML.

                  The only full support for HTML, CSS (and JS) is in QWebEnginePage, which really is HTML and is implemented via Chromium engine. I don't see anywhere that Qt has support for HTML.

                  I don't disagree with you that it's "a shame", but it is what it is!

                  1 Reply Last reply
                  1
                  • SPlattenS Offline
                    SPlattenS Offline
                    SPlatten
                    wrote on last edited by
                    #9

                    Not a problem, I'm creating a solution that will behave exactly the way CSS does and already has several benefits over QML.

                    Kind Regards,
                    Sy

                    JonBJ 1 Reply Last reply
                    0
                    • SPlattenS SPlatten

                      Not a problem, I'm creating a solution that will behave exactly the way CSS does and already has several benefits over QML.

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by
                      #10

                      @SPlatten
                      For the record, I imagine that implementing "80%" in a widgets app will need to go via QBoxLayout::setStretch() on the layout containing the widgets.

                      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