In Qt 5.7, the code created by Qt Designer for a horizontal line (which can be checked in the menu using "Form / View Code ..."):
QFrame *line; line = new QFrame(Form); line->setFrameShape(QFrame::HLine); line->setFrameShadow(QFrame::Sunken);
This will create the lines you see in Qt Designer.
The current answers do not seem to give working solutions, here is a comparison of all the answers (this solution is the first line):

Full code:
#include <QtWidgets> int main(int argc, char **argv) { QApplication app(argc, argv); QWidget widget; auto layout = new QVBoxLayout; widget.setLayout(layout); widget.resize(200, 200); auto lineA = new QFrame; lineA->setFrameShape(QFrame::HLine); lineA->setFrameShadow(QFrame::Sunken); layout->addWidget(lineA); QWidget *lineB = new QWidget; lineB->setFixedHeight(2); lineB->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); lineB->setStyleSheet(QString("background-color: #c0c0c0;")); layout->addWidget(lineB); auto lineC = new QFrame; lineC->setFixedHeight(3); lineC->setFrameShadow(QFrame::Sunken); lineC->setLineWidth(1); layout->addWidget(lineC); QFrame* lineD = new QFrame; lineD->setFrameShape(QFrame::HLine); layout->addWidget(lineD); widget.show(); return app.exec(); }
source share