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. Margins with repeated packaging of QWidgets
QtWS25 Last Chance

Margins with repeated packaging of QWidgets

Scheduled Pinned Locked Moved Solved General and Desktop
gui containersqwidgetcontentsmargins
6 Posts 3 Posters 1.7k 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
    koahnig
    wrote on last edited by
    #1

    Within Qt guis one may pack a couple of elements into a class derived from QWidget and use this new class as a new widget. One may do this even a couple of times. Apparently each time the space available for GUI elements does shrink a bit. Certainly this is important when there is also some reason to have some external distinction such as a frame, which needs of course some space.

    However, when using simply QWidget for packing only there are also apparently margins substracted each time. For larger widgets that is acceptable. When starting to pack different widgets into another and placing them into a QWidgetTable, this may become a nuisance.

    I have basically a radio button, which I have placed as QWidgetTableItem into a QWidgetTable. It looks fine as longas I am using only this radiobutton which is only in one column while all the other columns contain text.

    I have decided now to place more than simply one radiobutton there. Therefore, I have written a class derived from QWidget which basically holds several radiobuttons. I have added QHBoxLayout in order to have the radiobuttons nicely distributed.

    Suddenly the radiobuttons are no longer in the center of the field, but seem to add with each wrapping some margin. As a result the radiobutton are getting smaller. Resizing them gets them bigger, but they are definitely no longer in the center.

    Using setContentsMargins with values of 0 does not eliminate the complete "wasted" space. Is there another settings to used as well?

    Vote the answer(s) that helped you to solve your issue(s)

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      I remembered I did it and now it's weird... you can achieve this using QHBoxLayout::setMargin(int) and passing a 0. Strangely enough I can't find this method in the docs but I used it in the past and auto-complete finds it

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      K 2 Replies Last reply
      1
      • VRoninV VRonin

        I remembered I did it and now it's weird... you can achieve this using QHBoxLayout::setMargin(int) and passing a 0. Strangely enough I can't find this method in the docs but I used it in the past and auto-complete finds it

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

        @VRonin

        Here is the reason why you cannot find it setMargin

        However, I am not sure, it looks it might still have a marginal effect in Qt 5.4 (which I am using).

        Vote the answer(s) that helped you to solve your issue(s)

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

          Hi,

          Can you post a sample code to reproduce this ?

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

          K 1 Reply Last reply
          0
          • VRoninV VRonin

            I remembered I did it and now it's weird... you can achieve this using QHBoxLayout::setMargin(int) and passing a 0. Strangely enough I can't find this method in the docs but I used it in the past and auto-complete finds it

            K Offline
            K Offline
            koahnig
            wrote on last edited by
            #5

            @VRonin

            setMargin(0) has the same effect as setContentsMargins(0, 0, 0, 0) in Qt 5.4.
            As you pointed already out the documentation is missing. Apparently, it was kicked out because it was marked as obsolete.
            Either it was still active in Qt 4.8 and the term obsolete was premature or it slipped back in.

            Vote the answer(s) that helped you to solve your issue(s)

            1 Reply Last reply
            1
            • SGaistS SGaist

              Hi,

              Can you post a sample code to reproduce this ?

              K Offline
              K Offline
              koahnig
              wrote on last edited by
              #6

              @SGaist

              I have tried to get an example to the problem I saw apparently, but I did not succeed. For a simple radio button it is working, but the layout's margins need to be set to 0 either with setMargin or setContentsMargins.

              For the small example I have generated I had introduced also the derived class I used and it seems to work there. Therefore, there must be another problem with the QTableWidget's implementation or I simply fall into a trap.

              Therefore, I will mark as solved.

              Vote the answer(s) that helped you to solve your issue(s)

              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