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. [SOLVED] Customize QMdiArea QTabBar
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Customize QMdiArea QTabBar

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.1k 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.
  • A Offline
    A Offline
    alex_malyu
    wrote on last edited by
    #1

    My application has 2 QMdiAreas side by side with tabbed subwindows.
    Subwindows and thus tabs are closable.

    In both QTabBars active subwindow tabs are displayed with close buttons displaying its active status (enabled icon of close button)

    But I need to make only 1 tab appear to be active. So I do some custom handling to keep track of "active" mdi area.
    I can customize appearance of selected tab,
    but I also want to be able to customize appearance close tab behavior.

    Basically I only need to make on the specific mdi area all close tabs (even for active subwindow) to display inactive icon instead of active.

    I tried to set stylesheet to QTabBar as below

    @ tabBar->setStyleSheet(
    "QTabBar::close-button {"
    "image: url(:/trolltech/styles/commonstyle/images/standardbutton-closetab-16.png);"
    "}"
    );@

    But this always displays active icon of close button and I need disable (unless howered).
    And I would prefer not to create custom images.

    Am I missing any better way to do it?

    Thanks in advance,
    Alex

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      You could try using QProxyStyle instead, and manipulate the style option that is passed to the rendering code.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        alex_malyu
        wrote on last edited by
        #3

        @void CustomizeMdiProxyStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget ) const
        {
        Q_CHECK_PTR( widget );
        Q_CHECK_PTR( option );

        if( !buttonParent.isNull() && widget && buttonParent.data()!= widget && element == QStyle::PE_IndicatorTabClose && option )
        {
        const QTabBar* tabBar = qobject_cast<const QTabBar*>(widget);
        Q_CHECK_PTR( tabBar );

        QStyleOption opt( *option );
        opt.state &= ~( QStyle::State_Selected );

        QProxyStyle::drawPrimitive ( element, &opt, painter, widget );
        }
        else
        QProxyStyle::drawPrimitive(element, option, painter, widget);
        }@

        Solution can be broken in case of current implementation change but has the desired visual effect and keeps current style.

        Thanks Andre for suggestion.

        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