Important: Please read the Qt Code of Conduct -

How to customize the toolbar to work with a QTextEdit ?

  • Good evening to the whole community, I am writing to you because I am working on a text editor project and I am having difficulties with inserting the elements in the toolbar (QToolBar) and connecting this bar with the text box (QTextEdit). I actually wrote some code to create a tool that allows the user to choose the color of the text. This is the following code:
    QColor couleur= QColorDialog::getColor( Qt::black,this);
    QPalette palette ;
    But at the end of the code the QtCreator IDE tells me:
    no viable conversion from 'QPalette' to 'QWidget *'
    So I don't know how, I will insert this tool in the toolbar. I also inserted a tool for the font in the bar and I connected it to a slot of the QTextEdit. Here is the code:
    QFontComboBox *police = new QFontComboBox;
    When I generate the editor program (after removing the code on the color tool), when I change the font in the toolbar, the text font doesn't change and I don't know where my error is .
    Thank you for your answers in advance, good evening!

  • Lifetime Qt Champion


    It's your job to write the code that will apply the font to the current block of your QTextEdit.

    As for QPalette, the error tells it pretty clearly. It's not a QWidget based class. However your logic is not clear. What exactly do you want to when your selected the color ? Apply it to the text under the cursor ? Create an action that will trigger that that shows that selected color ?

  • @SGaist good evening I want the text which will then be written after selecting the color and as long as it is selected to use it
    Thank you

  • Lifetime Qt Champion

    Then get the current format, update it with the color and insert a new block with it.

  • @SGaist Sorry, but I'm not quite sure what you mean by the current format.
    Please answer.

  • Lifetime Qt Champion

    See for example QTextCurso::setCharFormat.

Log in to reply