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. Get margins of QPushButton

Get margins of QPushButton

Scheduled Pinned Locked Moved Solved General and Desktop
qtwidgetsqss
13 Posts 4 Posters 13.0k Views 4 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.
  • G Offline
    G Offline
    goldstar2154
    wrote on last edited by
    #3

    Shoud i open bug?) Have developers read this forum?

    raven-worxR 1 Reply Last reply
    0
    • G goldstar2154

      Shoud i open bug?) Have developers read this forum?

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #4

      @goldstar2154 said in Get margins of QPushButton:

      Shoud i open bug?
      Either open a bug or write to the dev mailing list as i wrote.

      Have developers read this forum?

      no this forum isn't read by the developers. The dev mailing list is.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        zhangsi
        wrote on last edited by
        #5

        you can call QPushButton::styleSheet function to get margin from string, why not

        raven-worxR 1 Reply Last reply
        0
        • Z zhangsi

          you can call QPushButton::styleSheet function to get margin from string, why not

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #6

          @zhangsi said in Get margins of QPushButton:

          you can call QPushButton::styleSheet function to get margin from string, why not

          if it just would be that easy...

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          2
          • C Offline
            C Offline
            CppHamster
            wrote on last edited by
            #7

            @goldstar2154 , @raven-worx Have you found how to solve this problem with qpushbutton margins in paintevent?

            raven-worxR 1 Reply Last reply
            0
            • C CppHamster

              @goldstar2154 , @raven-worx Have you found how to solve this problem with qpushbutton margins in paintevent?

              raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by raven-worx
              #8

              @CppHamster
              you can try the QStyle way:

              void QDelayPushButton::paintEvent(QPaintEvent* event)
              {
                    QPushButton::paintEvent(event);
              
                    QStyleOptionButton option;
                    this->initStyleOption(&option);
                    QRect contentsRect = this->style()->subElementRect( QStyle::SE_PushButtonLayoutItem, &option, this );
                    ...
              }
              

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              C 2 Replies Last reply
              1
              • raven-worxR raven-worx

                @CppHamster
                you can try the QStyle way:

                void QDelayPushButton::paintEvent(QPaintEvent* event)
                {
                      QPushButton::paintEvent(event);
                
                      QStyleOptionButton option;
                      this->initStyleOption(&option);
                      QRect contentsRect = this->style()->subElementRect( QStyle::SE_PushButtonLayoutItem, &option, this );
                      ...
                }
                
                C Offline
                C Offline
                CppHamster
                wrote on last edited by
                #9

                @raven-worx Thank you! But still does not work

                1 Reply Last reply
                0
                • raven-worxR raven-worx

                  @CppHamster
                  you can try the QStyle way:

                  void QDelayPushButton::paintEvent(QPaintEvent* event)
                  {
                        QPushButton::paintEvent(event);
                  
                        QStyleOptionButton option;
                        this->initStyleOption(&option);
                        QRect contentsRect = this->style()->subElementRect( QStyle::SE_PushButtonLayoutItem, &option, this );
                        ...
                  }
                  
                  C Offline
                  C Offline
                  CppHamster
                  wrote on last edited by
                  #10

                  @raven-worx finally, i've got the contents size by using your advice:
                  1: QRect contentsRect1 = this->style()->subElementRect( QStyle::SE_PushButtonLayoutItem, &option, this );
                  2: QRect contentsRect2 = this->style()->subElementRect( QStyle::SE_PushButtonContents, &option, this );
                  3: QRect contentsRect3 = this->style()->subElementRect( QStyle::SE_PushButtonFocusRect, &option, this );

                  qDebug() with QPushbutton properties:
                  width: 134
                  height: 45
                  .....
                  QMargins(0, 0, 0, 0) // <- QMargins margins = this->contentsMargins();
                  .....
                  1: QRect(0,0 0x0)
                  2: QRect(1,1 132x43)
                  3: QRect(1,1 132x43)

                  The difference is border width.

                  1 Reply Last reply
                  3
                  • C Offline
                    C Offline
                    CppHamster
                    wrote on last edited by
                    #11

                    @goldstar2154 if the code is correct, you can mark this question as "solved"

                    G 1 Reply Last reply
                    0
                    • C CppHamster

                      @goldstar2154 if the code is correct, you can mark this question as "solved"

                      G Offline
                      G Offline
                      goldstar2154
                      wrote on last edited by goldstar2154
                      #12

                      @CppHamster this code is correct technically, but not logically. If we have contentsMargins() method it shoud work...
                      P.S. i've marked question as solved, but still think is a bug
                      P.P.S. and thanks for solution, of course)

                      C 1 Reply Last reply
                      1
                      • G goldstar2154

                        @CppHamster this code is correct technically, but not logically. If we have contentsMargins() method it shoud work...
                        P.S. i've marked question as solved, but still think is a bug
                        P.P.S. and thanks for solution, of course)

                        C Offline
                        C Offline
                        CppHamster
                        wrote on last edited by CppHamster
                        #13

                        @goldstar2154 Totally agree with you - there is a obvious bug. But thanks to @raven-worx 's code we've got a way to get a result at least. And "solved" will help in web search:)
                        Thank you very much for this question:)

                        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