How to remove extra margin in QHBoxLayout



  • 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();
    }
    @



  • Hi,

    Try tabWidget.setTabShape(QTabWidget::Triangular).



  • Thanks, ckakman. It worked!!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.