Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. How to customize the toolbar to work with a QTextEdit ?
Forum Updated to NodeBB v4.3 + New Features

How to customize the toolbar to work with a QTextEdit ?

Scheduled Pinned Locked Moved Unsolved Qt 6
qtcreatorc++
6 Posts 2 Posters 1.4k 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.
  • G Offline
    G Offline
    gouneken
    wrote on last edited by
    #1

    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 ;
    palette.setColor(QPalette::WindowText,couleur);
    outils->addWidget(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:
    outils->setMovable(false);
    outils->setFloatable(false);
    QFontComboBox *police = new QFontComboBox;
    outils->addWidget(police);
    connect(police,SIGNAL(currentFontChanged()),texte1,SLOT(setFontFamily()));
    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!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      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 ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      G 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        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 ?

        G Offline
        G Offline
        gouneken
        wrote on last edited by
        #3

        @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

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

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

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          G 1 Reply Last reply
          0
          • SGaistS SGaist

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

            G Offline
            G Offline
            gouneken
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              See for example QTextCurso::setCharFormat.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              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