Keeping aspect ratio of images in a QTabBar
Unsolved
General and Desktop
-
I have a QTabWidget (tabWidget) and its QTabBar (tabBar). In each tab of tabBar there is an SVG image that is drawn. The SVGs are stored in a resource.
The problem is that the SVGs don't have the same aspect ration. So they are drawn streched. Is there a way to draw them so that they are not distorted and keep their original aspect ration?
Here is an excerpt of the code:
auto* stackedWidget = tabWidget->findChild<QStackedWidget*>(); stackedWidget->setAttribute(Qt::WA_ContentsMarginsRespectsSafeArea, false); tabWidget->setObjectName("myMenu"); tabWidget->tabBar()->setObjectName("myMenuTabBar"); tabWidget->tabBar()->installEventFilter(this); auto* tabWidgetStyle = new TabWidgetStyle(); tabWidgetStyle->setParent(tabWidget); tabWidget->setStyle(tabWidgetStyle); int tabIndex = 0; auto tabBar = tabWidget->tabBar(); tabIndex = tabWidget->addTab(widget1, ""); tabBar->setTabData(tabIndex, "FirstTab"); tabIndex = tabWidget->addTab(widget2, ""); tabBar->setTabData(tabIndex, "SecondTab");
FirstTab and SecondTab refers to the SVG files in resources. Thanks in advance!
Marc-Andre