Re: [Interest] How to programatically make a tab's text bold?

2018-04-04 Thread André Pönitz
On Wed, Apr 04, 2018 at 05:10:07AM +, Vadim Peretokin wrote:
> How can I programatically make a tab's text bold? I'm looking to notify the
> user that they need to look at it.
> 
> Note that this is different from using a stylesheet to set the selected tab
> bold - I'd like to set any random tab's text bold.
> 
> Been looking at this for several days, appreciate any advice!

Quick and dirty:

struct Style : QProxyStyle
{
void drawControl(ControlElement element, const QStyleOption *opt, QPainter 
*p, const QWidget *w) const
{
if (element == QStyle::CE_TabBarTab) {
QFont f = p->font();
f.setBold(true);
p->setFont(f);
}
QProxyStyle::drawControl(element, opt, p, w);
}
};

...
yourTabWidget()->tabBar()->>setStyle(new Style);


May need some polish.

Andre'

___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


Re: [Interest] How to programatically make a tab's text bold?

2018-04-04 Thread Vadim Peretokin
Thanks a ton! Works.

On Wed, Apr 4, 2018 at 12:07 PM Igor Mironchik 
wrote:

>
> #include 
> #include 
> #include 
> #include 
> #include 
> #include 
>
> class Style : public QProxyStyle
> {
> public:
> Style( QTabBar * bar )
> :m_boldTab( 0 )
> ,m_bar( bar )
> {
> }
>
> ~Style()
> {
> }
>
> void drawControl( ControlElement element,
> const QStyleOption *option,
> QPainter *painter,
> const QWidget *widget = Q_NULLPTR) const
> {
> if( element == QStyle::CE_TabBarTab )
> {
> if( m_bar->tabAt( option->rect.center() ) == m_boldTab )
> {
> QFont font = widget->font();
> font.setBold( true );
>
> painter->save();
> painter->setFont( font );
> QProxyStyle::drawControl( element, option, painter, widget
> );
> painter->restore();
> }
> else
> QProxyStyle::drawControl( element, option, painter, widget
> );
> }
> else
> QProxyStyle::drawControl( element, option, painter, widget );
> }
>
> private:
> int m_boldTab;
> QTabBar * m_bar;
> };
>
> class Tab : public QTabBar
> {
> public:
> Tab( QWidget * parent )
> :QTabBar( parent )
> ,m_boldTab( 0 )
> {
> }
>
> ~Tab()
> {
> }
>
> protected:
> QSize tabSizeHint(int index) const
> {
> if( index == m_boldTab )
> {
> const QSize s = QTabBar::tabSizeHint( index );
> const QFontMetrics fm( font() );
> const int w = fm.width( tabText( index ) );
>
> QFont f = font();
> f.setBold( true );
> const QFontMetrics bfm( f );
>
> const int bw = bfm.width( tabText( index ) );
>
> return QSize( s.width() - w + bw, s.height() );
> }
> else
> return QTabBar::tabSizeHint( index );
> }
>
> private:
> int m_boldTab;
> };
>
> class TabWidget
> :public QTabWidget
> {
> public:
> TabWidget()
> :m_tabBar( new Tab( this ) )
> ,m_style( m_tabBar )
> {
> m_tabBar->setStyle( _style );
> setTabBar( m_tabBar );
> }
>
> ~TabWidget()
> {
> }
>
> private:
> Tab * m_tabBar;
> Style m_style;
> };
>
> int main( int argc, char ** argv )
> {
> QApplication app( argc, argv );
>
> TabWidget t;
> QWidget w1, w2;
> t.addTab( , "Test Tab With Long Name" );
> t.addTab( , "Second Tab" );
>
> t.show();
>
> return app.exec();
> }
>
>
> On 04.04.2018 10:47, Vadim Peretokin wrote:
>
>
> On Wed, Apr 4, 2018 at 7:35 AM Hamish Moffatt 
> wrote:
>
>> On 04/04/18 15:10, Vadim Peretokin wrote:
>> > How can I programatically make a tab's text bold? I'm looking to
>> > notify the user that they need to look at it.
>> >
>> > Note that this is different from using a stylesheet to set the
>> > selected tab bold - I'd like to set any random tab's text bold.
>> >
>> > Been looking at this for several days, appreciate any advice!
>>
>> Using widgets? You didn't say what context.
>>
>> Maybe you can set a dynamic property on the tab when you want it to be
>> bold, and attach a special style using properties in the stylesheet.
>>
>>
>> Hamish
>> ___
>> Interest mailing list
>> Interest@qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
>>
>
> Yes, using widgets.
>
> 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?
>
>
> ___
> Interest mailing 
> listInterest@qt-project.orghttp://lists.qt-project.org/mailman/listinfo/interest
>
>
> ___
> Interest mailing list
> Interest@qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


Re: [Interest] How to programatically make a tab's text bold?

2018-04-04 Thread Igor Mironchik


#include 
#include 
#include 
#include 
#include 
#include 

class Style : public QProxyStyle
{
public:
    Style( QTabBar * bar )
        :    m_boldTab( 0 )
        ,    m_bar( bar )
    {
    }

    ~Style()
    {
    }

    void drawControl( ControlElement element,
        const QStyleOption *option,
        QPainter *painter,
        const QWidget *widget = Q_NULLPTR) const
    {
        if( element == QStyle::CE_TabBarTab )
        {
            if( m_bar->tabAt( option->rect.center() ) == m_boldTab )
            {
                QFont font = widget->font();
                font.setBold( true );

                painter->save();
                painter->setFont( font );
                QProxyStyle::drawControl( element, option, painter, 
widget );

                painter->restore();
            }
            else
                QProxyStyle::drawControl( element, option, painter, 
widget );

        }
        else
            QProxyStyle::drawControl( element, option, painter, widget );
    }

private:
    int m_boldTab;
    QTabBar * m_bar;
};

class Tab : public QTabBar
{
public:
    Tab( QWidget * parent )
        :    QTabBar( parent )
        ,    m_boldTab( 0 )
    {
    }

    ~Tab()
    {
    }

protected:
    QSize tabSizeHint(int index) const
    {
        if( index == m_boldTab )
        {
            const QSize s = QTabBar::tabSizeHint( index );
            const QFontMetrics fm( font() );
            const int w = fm.width( tabText( index ) );

            QFont f = font();
            f.setBold( true );
            const QFontMetrics bfm( f );

            const int bw = bfm.width( tabText( index ) );

            return QSize( s.width() - w + bw, s.height() );
        }
        else
            return QTabBar::tabSizeHint( index );
    }

private:
    int m_boldTab;
};

class TabWidget
    :    public QTabWidget
{
public:
    TabWidget()
        :    m_tabBar( new Tab( this ) )
        ,    m_style( m_tabBar )
    {
        m_tabBar->setStyle( _style );
        setTabBar( m_tabBar );
    }

    ~TabWidget()
    {
    }

private:
    Tab * m_tabBar;
    Style m_style;
};

int main( int argc, char ** argv )
{
    QApplication app( argc, argv );

    TabWidget t;
    QWidget w1, w2;
    t.addTab( , "Test Tab With Long Name" );
    t.addTab( , "Second Tab" );

    t.show();

    return app.exec();
}


On 04.04.2018 10:47, Vadim Peretokin wrote:


On Wed, Apr 4, 2018 at 7:35 AM Hamish Moffatt 
> wrote:


On 04/04/18 15:10, Vadim Peretokin wrote:
> How can I programatically make a tab's text bold? I'm looking to
> notify the user that they need to look at it.
>
> Note that this is different from using a stylesheet to set the
> selected tab bold - I'd like to set any random tab's text bold.
>
> Been looking at this for several days, appreciate any advice!

Using widgets? You didn't say what context.

Maybe you can set a dynamic property on the tab when you want it to be
bold, and attach a special style using properties in the stylesheet.


Hamish
___
Interest mailing list
Interest@qt-project.org 
http://lists.qt-project.org/mailman/listinfo/interest


Yes, using widgets.

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?



___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


Re: [Interest] How to programatically make a tab's text bold?

2018-04-04 Thread René Hansen
Alternatively suffix an asterisk; Tab -> Tab*. Then remove it on highlight.

/René

On Wed, 4 Apr 2018 at 09:47 Vadim Peretokin  wrote:

> On Wed, Apr 4, 2018 at 7:35 AM Hamish Moffatt 
> wrote:
>
>> On 04/04/18 15:10, Vadim Peretokin wrote:
>> > How can I programatically make a tab's text bold? I'm looking to
>> > notify the user that they need to look at it.
>> >
>> > Note that this is different from using a stylesheet to set the
>> > selected tab bold - I'd like to set any random tab's text bold.
>> >
>> > Been looking at this for several days, appreciate any advice!
>>
>> Using widgets? You didn't say what context.
>>
>> Maybe you can set a dynamic property on the tab when you want it to be
>> bold, and attach a special style using properties in the stylesheet.
>>
>>
>> Hamish
>> ___
>> Interest mailing list
>> Interest@qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
>>
>
> Yes, using widgets.
>
> 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?
> ___
> Interest mailing list
> Interest@qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


Re: [Interest] How to programatically make a tab's text bold?

2018-04-04 Thread Vadim Peretokin
On Wed, Apr 4, 2018 at 7:35 AM Hamish Moffatt 
wrote:

> On 04/04/18 15:10, Vadim Peretokin wrote:
> > How can I programatically make a tab's text bold? I'm looking to
> > notify the user that they need to look at it.
> >
> > Note that this is different from using a stylesheet to set the
> > selected tab bold - I'd like to set any random tab's text bold.
> >
> > Been looking at this for several days, appreciate any advice!
>
> Using widgets? You didn't say what context.
>
> Maybe you can set a dynamic property on the tab when you want it to be
> bold, and attach a special style using properties in the stylesheet.
>
>
> Hamish
> ___
> Interest mailing list
> Interest@qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>

Yes, using widgets.

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?
___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


Re: [Interest] How to programatically make a tab's text bold?

2018-04-03 Thread Hamish Moffatt

On 04/04/18 15:10, Vadim Peretokin wrote:
How can I programatically make a tab's text bold? I'm looking to 
notify the user that they need to look at it.


Note that this is different from using a stylesheet to set the 
selected tab bold - I'd like to set any random tab's text bold.


Been looking at this for several days, appreciate any advice!


Using widgets? You didn't say what context.

Maybe you can set a dynamic property on the tab when you want it to be 
bold, and attach a special style using properties in the stylesheet.



Hamish
___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest