QScrollBar *scrollBar = new QScrollBar(Qt::Horizontal); scrollBar->setStyleSheet("QScrollBar:horizontal { height: 20px; background: #fff; }" "QScrollBar::handle:horizontal { background: #ccc; }");
QScrollBar *scrollBar = new QScrollBar(Qt::Vertical); scrollBar->setStyleSheet("QScrollBar:vertical { width: 20px; background: #fff; }" "QScrollBar::handle:vertical { background: #ccc; }");This code creates a vertical scrollbar, sets its width to 20 pixels and background color to white. The handle of the scrollbar is styled with a gray background color. The package library for QScrollBar and setStyleSheet() method is Qt Core Library.