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 remove extra margin in QHBoxLayout
Forum Updated to NodeBB v4.3 + New Features

How to remove extra margin in QHBoxLayout

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.6k 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.
  • S Offline
    S Offline
    shinichy
    wrote on last edited by
    #1

    I want this red label to fill from top to bottom in the window, but there's slight space between bottom of the title bar and top of the label.

    Does anyone know how to eliminate this extra margin?

    Environment:
    Qt 5.4, Mac OS X 10.9.5

    !http://i.stack.imgur.com/rhimv.png!

    @
    #include <QApplication>
    #include <QHBoxLayout>
    #include <QTabWidget>
    #include <QLabel>
    #include <QPlainTextEdit>

    int main(int argc, char* argv[]) {
    QApplication app(argc, argv);

    QTabWidget tabWidget;
    tabWidget.addTab(new QPlainTextEdit, "foo");

    QLabel label("label");
    label.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    label.setStyleSheet("QLabel{background-color: red;}");

    QHBoxLayout layout;
    layout.setContentsMargins(0, 0, 0, 0);
    layout.setSpacing(0);
    layout.addWidget(&tabWidget);
    layout.addWidget(&label);

    QWidget* widget = new QWidget();
    widget->setLayout(&layout);
    widget->show();

    return app.exec();
    }
    @

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ckakman
      wrote on last edited by
      #2

      Hi,

      Try tabWidget.setTabShape(QTabWidget::Triangular).

      1 Reply Last reply
      0
      • S Offline
        S Offline
        shinichy
        wrote on last edited by
        #3

        Thanks, ckakman. It worked!!

        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