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 Stylesheet: Margins of childwidgets
Forum Updated to NodeBB v4.3 + New Features

Qt Stylesheet: Margins of childwidgets

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 3.7k 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.
  • jensen82J Offline
    jensen82J Offline
    jensen82
    wrote on last edited by
    #1

    Hi!

    I'm using qss to style my ui. I have a QMainWindow with a centralWidget and the centralwidget has a layout that contains widgets. If i set margins in qss for centralwidget, the widgets in the layout of the centralwidget do not recognize the margins. Whats wrong?

    I see that the middle has the margins, but not the headerpanel i created. Some code:
    @void MainCentralWidget::setupUi()
    {
    mainLayout = new QVBoxLayout(this);
    mainLayout->setMargin(0);
    mainLayout->setSpacing(0);
    headerPanel = new BackgroundPanel(this);
    mainLayout->addWidget(headerPanel, 1, Qt::AlignTop);
    headerPanel->setMainWindow(parentWidget());
    headerPanel->setMainWindowDraggingActive(true);
    setLayout(mainLayout);
    }@

    And this is the css:

    @MainCentralWidget {
    background-image: url(styles/default/images/bgmain.jpg);
    background-repeat: no-repeat;
    background-position: bottom right;
    margin: 10px;
    }@

    Now, the header panel is at full size, no margins.

    And here's a screen:

    !http://s14.directupload.net/images/130803/bk3429nh.jpg(margin)!

    Any ideas? Or is it true that i have to set the margin for each widget

    1 Reply Last reply
    0
    • jensen82J Offline
      jensen82J Offline
      jensen82
      wrote on last edited by
      #2

      no ideas? Do i really have to set the margins for each widget? Also if it is a child of a widget with margins?

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

        Hi,

        If I am not mistaken your style sheet is only for your MainCentralWidget so It won't apply to other widgets.

        You have to make a more generic style sheet for QWidget for example and prepend it to your current style sheet.

        Hope it helps

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

        1 Reply Last reply
        0
        • jensen82J Offline
          jensen82J Offline
          jensen82
          wrote on last edited by
          #4

          So...child widgets are not part of the style? I expected that if i set the margin of a widget, the child widget in the parent layout also has the margins.

          It works if i set the the margins of the child-widget. I dont want to set the margin of QWidget because every Qwidget then has the margin...that's not what i want.

          1 Reply Last reply
          0
          • jensen82J Offline
            jensen82J Offline
            jensen82
            wrote on last edited by
            #5

            BTW: Thank you for your answer :-)

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

              You're welcome :)

              Basically no, each widget is independent for that.

              You could however use this "technique":http://qt-project.org/doc/qt-5.0/qtwidgets/stylesheet-examples.html#customizing-using-dynamic-properties for your child widgets

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

              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