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
Forum Updated to NodeBB v4.3 + New Features

Get margins of QPushButton

Scheduled Pinned Locked Moved Solved General and Desktop
qtwidgetsqss
13 Posts 4 Posters 11.9k 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 goldstar2154
    25 Aug 2017, 10:29

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

    R Offline
    R Offline
    raven-worx
    Moderators
    wrote on 25 Aug 2017, 10:38 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 30 Aug 2017, 03:02 last edited by
      #5

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

      R 1 Reply Last reply 30 Aug 2017, 06:59
      0
      • Z zhangsi
        30 Aug 2017, 03:02

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

        R Offline
        R Offline
        raven-worx
        Moderators
        wrote on 30 Aug 2017, 06:59 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 13 Sept 2017, 08:11 last edited by
          #7

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

          R 1 Reply Last reply 13 Sept 2017, 08:17
          0
          • C CppHamster
            13 Sept 2017, 08:11

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

            R Offline
            R Offline
            raven-worx
            Moderators
            wrote on 13 Sept 2017, 08:17 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 13 Sept 2017, 15:05
            1
            • R raven-worx
              13 Sept 2017, 08:17

              @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 13 Sept 2017, 15:05 last edited by
              #9

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

              1 Reply Last reply
              0
              • R raven-worx
                13 Sept 2017, 08:17

                @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 13 Sept 2017, 15:45 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 20 Sept 2017, 10:44 last edited by
                  #11

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

                  G 1 Reply Last reply 20 Sept 2017, 13:21
                  0
                  • C CppHamster
                    20 Sept 2017, 10:44

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

                    G Offline
                    G Offline
                    goldstar2154
                    wrote on 20 Sept 2017, 13:21 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 20 Sept 2017, 17:10
                    1
                    • G goldstar2154
                      20 Sept 2017, 13:21

                      @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 20 Sept 2017, 17:10 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