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. How to read QWidget style margin?

How to read QWidget style margin?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 567 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.
  • K Offline
    K Offline
    Kattia
    wrote on last edited by
    #1

    I'm working on a customizable QComboBox, i'm trying to find a way to read the QAbstractItemView margin, when its modified from a stylesheet, for example:

    QComboBox QAbstractItemView 
    {
    	background-color: rgba(40, 40, 40, 180);
    	border-radius: 8px;
    	margin: 30px;
    }
    

    I tried to read the margin as:

    void ComboBox::showPopup() override
    {
            // ...
            QWidget* comboWindow = view()->window();
            QStyle* style = comboWindow->style();
            int margin = style->pixelMetric(QStyle::PM_LayoutLeftMargin, nullptr, comboWindow);
            // ...
    }
    

    But it returned 11, i have no idea what this means, how I could get the margin without relying on parsing it from
    widget->styleSheet()

    JonBJ 1 Reply Last reply
    0
    • K Kattia

      I'm working on a customizable QComboBox, i'm trying to find a way to read the QAbstractItemView margin, when its modified from a stylesheet, for example:

      QComboBox QAbstractItemView 
      {
      	background-color: rgba(40, 40, 40, 180);
      	border-radius: 8px;
      	margin: 30px;
      }
      

      I tried to read the margin as:

      void ComboBox::showPopup() override
      {
              // ...
              QWidget* comboWindow = view()->window();
              QStyle* style = comboWindow->style();
              int margin = style->pixelMetric(QStyle::PM_LayoutLeftMargin, nullptr, comboWindow);
              // ...
      }
      

      But it returned 11, i have no idea what this means, how I could get the margin without relying on parsing it from
      widget->styleSheet()

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

      @Kattia
      To the best of my knowledge and as asked in the past, stylesheet overrides style. You cannot discover in code the effects of stylesheet, and would have to parse if you needed that information.

      P.S.
      To clarify: not that this is ideal, it's just how it is. JavaScript from HTML, for example, gives you access to current style from applied stylesheet rules, but sadly Qt does not seem to do so.

      K 1 Reply Last reply
      2
      • JonBJ JonB

        @Kattia
        To the best of my knowledge and as asked in the past, stylesheet overrides style. You cannot discover in code the effects of stylesheet, and would have to parse if you needed that information.

        P.S.
        To clarify: not that this is ideal, it's just how it is. JavaScript from HTML, for example, gives you access to current style from applied stylesheet rules, but sadly Qt does not seem to do so.

        K Offline
        K Offline
        Kattia
        wrote on last edited by Kattia
        #3

        @JonB and if you don't know from where the stylesheet comes? like when you set the stylesheet on a parent and its applied to children's.

        JonBJ 1 Reply Last reply
        0
        • K Kattia

          @JonB and if you don't know from where the stylesheet comes? like when you set the stylesheet on a parent and its applied to children's.

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

          @Kattia
          Yep, you would have to figure out inheritance for yourself (e.g. recurse up in your case).
          Since you're not going to do it, try not to need to know such a detail.

          1 Reply Last reply
          0
          • K Offline
            K Offline
            Kattia
            wrote on last edited by
            #5

            @JonB said in How to read QWidget style margin?:

            try not to need to know such a detail.

            nice, and how ill find the data i need?

            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