hello everyone, I’m new here.
I write here to find some help about qt coding, in this case about Text Edit demo ( ttp//qt-project.org/doc/qt-4.8/demos-textedit.html ).
To better learning qt coding (i am a newbie about developing/coding), i am adding features/improvements on Text Edit: for now i have added the ability to choose the color of background text, and now i’d like add the ability to choose the background color of the whole sheet/document.
This is the part of code about color picker/selector:
pix.fill(Qt::white);
actionBackgroundColor = new QAction(QIcon::fromTheme("bg-color", QIcon(rsrcPath + "/colorpicker.png")),
tr("&Background Color..."), this);
connect(actionBackgroundColor, SIGNAL(triggered()), this, SLOT(backgroundColor()));
tb->addAction(actionBackgroundColor);
menu->addAction(actionBackgroundColor);
And the following is the part of code which should insert the html tag about bg color:
void TextEdit::backgroundColor()
{
QColor color = QColorDialog::getColor(Qt::white, this);
if (color.isValid())
textEdit->insertHtml("<body bgcolor="" + fn + """);
}
When i compile Text Edit with this code, a new color selector is added to toolbar, but choosing the color doesn’t affects the document. Could someone tell me where the code is wrong and how can I fix it?
Thank you very much.
↧