<div dir="ltr">Thanks a ton! Works.<br></div><br><div class="gmail_quote"><div dir="ltr">On Wed, Apr 4, 2018 at 12:07 PM Igor Mironchik <<a href="mailto:igor.mironchik@gmail.com">igor.mironchik@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div bgcolor="#FFFFFF" text="#000000">
    <p><br>
      #include <QTabWidget><br>
      #include <QApplication><br>
      #include <QTabBar><br>
      #include <QProxyStyle><br>
      #include <QPainter><br>
      #include <QStyleOption><br>
      <br>
      class Style : public QProxyStyle<br>
      {<br>
      public:<br>
          Style( QTabBar * bar )<br>
              :    m_boldTab( 0 )<br>
              ,    m_bar( bar )<br>
          {<br>
          }<br>
      <br>
          ~Style()<br>
          {<br>
          }<br>
      <br>
          void drawControl( ControlElement element,<br>
              const QStyleOption *option,<br>
              QPainter *painter,<br>
              const QWidget *widget = Q_NULLPTR) const<br>
          {<br>
              if( element == QStyle::CE_TabBarTab )<br>
              {<br>
                  if( m_bar->tabAt( option->rect.center() ) ==
      m_boldTab )<br>
                  {<br>
                      QFont font = widget->font();<br>
                      font.setBold( true );<br>
      <br>
                      painter->save();<br>
                      painter->setFont( font );<br>
                      QProxyStyle::drawControl( element, option,
      painter, widget );<br>
                      painter->restore();<br>
                  }<br>
                  else<br>
                      QProxyStyle::drawControl( element, option,
      painter, widget );<br>
              }<br>
              else<br>
                  QProxyStyle::drawControl( element, option, painter,
      widget );<br>
          }<br>
      <br>
      private:<br>
          int m_boldTab;<br>
          QTabBar * m_bar;<br>
      };<br>
      <br>
      class Tab : public QTabBar<br>
      {<br>
      public:<br>
          Tab( QWidget * parent )<br>
              :    QTabBar( parent )<br>
              ,    m_boldTab( 0 )<br>
          {<br>
          }<br>
      <br>
          ~Tab()<br>
          {<br>
          }<br>
      <br>
      protected:<br>
          QSize tabSizeHint(int index) const<br>
          {<br>
              if( index == m_boldTab )<br>
              {<br>
                  const QSize s = QTabBar::tabSizeHint( index );<br>
                  const QFontMetrics fm( font() );<br>
                  const int w = fm.width( tabText( index ) );<br>
      <br>
                  QFont f = font();<br>
                  f.setBold( true );<br>
                  const QFontMetrics bfm( f );<br>
      <br>
                  const int bw = bfm.width( tabText( index ) );<br>
      <br>
                  return QSize( s.width() - w + bw, s.height() );<br>
              }<br>
              else<br>
                  return QTabBar::tabSizeHint( index );<br>
          }<br>
      <br>
      private:<br>
          int m_boldTab;<br>
      };<br>
      <br>
      class TabWidget<br>
          :    public QTabWidget<br>
      {<br>
      public:<br>
          TabWidget()<br>
              :    m_tabBar( new Tab( this ) )<br>
              ,    m_style( m_tabBar )<br>
          {<br>
              m_tabBar->setStyle( &m_style );<br>
              setTabBar( m_tabBar );<br>
          }<br>
      <br>
          ~TabWidget()<br>
          {<br>
          }<br>
      <br>
      private:<br>
          Tab * m_tabBar;<br>
          Style m_style;<br>
      };<br>
      <br>
      int main( int argc, char ** argv )<br>
      {<br>
          QApplication app( argc, argv );<br>
      <br>
          TabWidget t;<br>
          QWidget w1, w2;<br>
          t.addTab( &w1, "Test Tab With Long Name" );<br>
          t.addTab( &w2, "Second Tab" );<br>
      <br>
          t.show();<br>
      <br>
          return app.exec();<br>
      }<br>
      <br>
    </p></div><div bgcolor="#FFFFFF" text="#000000">
    <br>
    <div class="m_7288718780705825990moz-cite-prefix">On 04.04.2018 10:47, Vadim Peretokin
      wrote:<br>
    </div>
    <blockquote type="cite">
      <div dir="ltr">
        <div dir="ltr">
          <div><br>
            <div class="gmail_quote">
              <div dir="ltr">On Wed, Apr 4, 2018 at 7:35 AM Hamish
                Moffatt <<a href="mailto:hamish@risingsoftware.com" target="_blank">hamish@risingsoftware.com</a>>
                wrote:<br>
              </div>
              <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On
                04/04/18 15:10, Vadim Peretokin wrote:<br>
                > How can I programatically make a tab's text bold?
                I'm looking to<br>
                > notify the user that they need to look at it.<br>
                ><br>
                > Note that this is different from using a stylesheet
                to set the<br>
                > selected tab bold - I'd like to set any random
                tab's text bold.<br>
                ><br>
                > Been looking at this for several days, appreciate
                any advice!<br>
                <br>
                Using widgets? You didn't say what context.<br>
                <br>
                Maybe you can set a dynamic property on the tab when you
                want it to be<br>
                bold, and attach a special style using properties in the
                stylesheet.<br>
                <br>
                <br>
                Hamish<br>
                _______________________________________________<br>
                Interest mailing list<br>
                <a href="mailto:Interest@qt-project.org" target="_blank">Interest@qt-project.org</a><br>
                <a href="http://lists.qt-project.org/mailman/listinfo/interest" rel="noreferrer" target="_blank">http://lists.qt-project.org/mailman/listinfo/interest</a><br>
              </blockquote>
              <div><br>
                <div>Yes, using widgets.<br>
                  <br>
                </div>
                I've tried a dynamic property however as far as I can
                see, I can only set the dynamic property on the entire
                tab bar - not a specific tab. How can I set it on a
                specific tab? <br>
              </div>
            </div>
          </div>
        </div>
      </div>
      <br>
      <fieldset class="m_7288718780705825990mimeAttachmentHeader"></fieldset>
      <br>
      <pre>_______________________________________________
Interest mailing list
<a class="m_7288718780705825990moz-txt-link-abbreviated" href="mailto:Interest@qt-project.org" target="_blank">Interest@qt-project.org</a>
<a class="m_7288718780705825990moz-txt-link-freetext" href="http://lists.qt-project.org/mailman/listinfo/interest" target="_blank">http://lists.qt-project.org/mailman/listinfo/interest</a>
</pre>
    </blockquote>
    <br>
  </div>

_______________________________________________<br>
Interest mailing list<br>
<a href="mailto:Interest@qt-project.org" target="_blank">Interest@qt-project.org</a><br>
<a href="http://lists.qt-project.org/mailman/listinfo/interest" rel="noreferrer" target="_blank">http://lists.qt-project.org/mailman/listinfo/interest</a><br>
</blockquote></div>