QBarSet; SetLabelColor & SetLabelFont don't work. Qt failure?



  • Hello community, (I Use Qt 5.11.2 on Windows with msvc15)

    I would like to adjust the Font style and the size in aQBarSet.
    From the beginning the simplest settings don't work

    I tried the next code:

    set2 = new QBarSet("MyText", this);
     QFont myDesiredText = QString("my_Desired_Text");
     myDesiredText.setPointSize(2);
     myDesiredText.setBold(1);
     set2->setLabel("MySecondText");            //work
     set2->setLabelColor(Qt::red);              //don't work
     set2->setLabelFont(myDesiredText);         //don't work
    

    The Label shoes at the end "MySecond text".

    I think that's an issue in Qt or perhaps I did't make the things fine.
    Please, could somebody show me how to configure the font type and its size in a QBarset?
    (I googled, but not successfully)

    thanks in advance.



  • @Josz

    Try to change the sequence and use use larger point size for a start e.g.:

    set2 = new QBarSet("MyText", this);
     QFont myDesiredText = QString("my_Desired_Text");
     myDesiredText.setPointSize(12);
     myDesiredText.setBold(true);
     set2->setLabelColor(Qt::red);       
     set2->setLabelFont(myDesiredText);
     set2->setLabel("MySecondText"); 
    


  • @koahnig Thank you very much

    Sadly didn't work.

    I tried:

      set2 = new QBarSet("MyText", this);
      QFont myDesiredText = QString("my_Desired_Text");
      myDesiredText.setPointSize(12);
      myDesiredText.setBold(true);
      set2->setLabelColor(Qt::red);
      set2->setLabelFont(myDesiredText);
    

    and the label shows "MyText" of the first line :-(



  • @Josz
    I guess that you need at least the statement

    set2->setLabel("MySecondText"); 
    

    at the end.


  • Moderators

    @Josz said in QBarSet; SetLabelColor & SetLabelFont don't work. Qt failure?:

    QFont myDesiredText = QString("my_Desired_Text");

    what do you expect that this line does?
    Is there a font named my_Desired_Text?!

    Also you may want to try setLabelBrush(Qt::red)



  • @raven-worx Thanks raven

    I tried

      set2 = new QBarSet("MyText", this);
      QFont *font = new QFont("Helvetica",13,13,true);
      //font->setPixelSize(2);
      set2->setLabelFont(*font);
      set2->setLabelBrush(Qt::red);
      set2->setLabel("MySecondText");
    

    don't works either :-(



  • I found a solution. Not the expected, for this reason I will not mark it as solved, but works

        QString thresholdText = "Threshold " + QString::number(threshold);
        set2->setLabel("<b><font size=4 face = 'Nina'>"+thresholdText+"</font></b>");
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.