Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Keeping aspect ratio of images in a QTabBar
Forum Updated to NodeBB v4.3 + New Features

Keeping aspect ratio of images in a QTabBar

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtabbaraspect ratiosvg
1 Posts 1 Posters 222 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SimplyBlue
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved