How to click on the image, hold from a corner of it, and resize the image in the QTextEdit? Or at least how to get an image under cursor/that is selected in order to change width and hight?
A:
You better use Qgraphicsitem instead of QTextEdit.. hope this link would be helpful for you
Shadow
2010-09-16 06:08:29
My be.... But I use QTextEdit.
Narek
2010-10-20 10:41:39
A:
Here how I have implemented:
void AdvancedTextEdit::resizeImage()
{
QTextBlock currentBlock = m_textEdit->textCursor().block();
QTextBlock::iterator it;
for (it = currentBlock.begin(); !(it.atEnd()); ++it)
{
QTextFragment fragment = it.fragment();
if (fragment.isValid())
{
if(fragment.charFormat().isImageFormat ())
{
QTextImageFormat newImageFormat = fragment.charFormat().toImageFormat();
QPair<double, double> size = ResizeImageDialog::getNewSize(this, newImageFormat.width(), newImageFormat.height());
newImageFormat.setWidth(size.first);
newImageFormat.setHeight(size.second);
if (newImageFormat.isValid())
{
//QMessageBox::about(this, "Fragment", fragment.text());
//newImageFormat.setName(":/icons/text_bold.png");
QTextCursor helper = m_textEdit->textCursor();
helper.setPosition(fragment.position());
helper.setPosition(fragment.position() + fragment.length(),
QTextCursor::KeepAnchor);
helper.setCharFormat(newImageFormat);
}
}
}
}
}
Of course I have implemented also the ResizeImageDialog dialog's getNewSize(this, newImageFormat.width(), newImageFormat.height()); function that gets the current size of image and lets user to chnage the size, and returns the new size of image as a QPair. This is not hard to do. See here for the implementation of the dialog.
Narek
2010-10-20 10:47:19