For first I must explain something.
I would like to do the chat widget.
So I started with the QTextBrowser.
After adding 80 lines(every line contained 30 pictures(16x16px gif)), the QTextBrowser turned out to be too slow(slow selecting text, slow srolling, etc.).
So perhaps would the QListWidget(with rich text items) be good for chat presentation?
OK. I downloaded http://www.qtcentre.org/forum/attach...3&d=1188673979.
I changed in maindialog.cpp lines:
<< "The <b>QListWidgetItem</b> class provides an item for use with the QListWidget item view class. The <b>QListWidgetItem</b> class provides an item for use with the QListWidget item view class. The <b>QListWidgetItem</b> class provides an item for use with the QListWidget item view class."
<< "The <b>QObject</b> class is the base class of all Qt objects."
<< "Qt's <b>drag and drop</b> infrastructure is fully supported by the model/view framework. Items in lists, tables, and trees can be dragged within the views, and data can be imported and exported as MIME-encoded data.";
<< "The <b>QListWidgetItem</b> class provides an item for use with the QListWidget item view class. The <b>QListWidgetItem</b> class provides an item for use with the QListWidget item view class. The <b>QListWidgetItem</b> class provides an item for use with the QListWidget item view class."
<< "The <b>QObject</b> class is the base class of all Qt objects."
<< "Qt's <b>drag and drop</b> infrastructure is fully supported by the model/view framework. Items in lists, tables, and trees can be dragged within the views, and data can be imported and exported as MIME-encoded data.";
To copy to clipboard, switch view to plain text mode
to:
<< "<font size=\"6\">The <b>QListWidgetItem</b> class."
<< "The <b>QObject</b> class is the base class of all Qt objects."
<< "Qt's <b>drag and drop</b>";
<< "<font size=\"6\">The <b>QListWidgetItem</b> class."
<< "The <b>QObject</b> class is the base class of all Qt objects."
<< "Qt's <b>drag and drop</b>";
To copy to clipboard, switch view to plain text mode
Result is wrong, because the text "The QListWidgetItem class." is covering the different text(See attachment.)
In sectionitem.cpp I changed in function:
QSize SectionItem
::sizeHint(QObject *parent,
const QStyleOptionViewItem
& option,
const QModelIndex
& index
) const {
float rw = float(p->viewport()->size().width());
float tw = fm.width(itemText);
float ratio = tw/rw;
int lines = int(ratio) + 1;
return QSize(rw, lines
* fm.
height());
}
QSize SectionItem::sizeHint(QObject *parent, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
QListWidget *p = (QListWidget*)parent;
QFontMetrics fm(p->font());
float rw = float(p->viewport()->size().width());
float tw = fm.width(itemText);
float ratio = tw/rw;
int lines = int(ratio) + 1;
return QSize(rw, lines * fm.height());
}
To copy to clipboard, switch view to plain text mode
one line:
int lines = int(ratio) + 2;
int lines = int(ratio) + 2;
To copy to clipboard, switch view to plain text mode
That works fine, but only when I don't resize widget and when text is "<font size=\"6\">The <b>QListWidgetItem</b> class.".
How to calculate the number of lines dynamically, if the text have different lenght and font sizes?
Bookmarks