QStyleOptionButton opt; opt.initFrom(button); // assume that `button` is a QPushButton QRect labelRect = QApplication::style()->subElementRect(QStyle::SE_PushButtonLabel, &opt, button);
QStyleOptionSlider opt; opt.initFrom(scrollBar); // assume that `scrollBar` is a QScrollBar QRect sliderRect = QApplication::style()->subElementRect(QStyle::SE_ScrollBarSlider, &opt, scrollBar);In this example, we initialize a QStyleOptionSlider object with the settings of a QScrollBar, and then use the subElementRect function to get the rectangle of the scrollbar's slider. The QStyle subElementRect function is part of the QtCore module of the Qt library.