QStyleOptionViewItem option; option.text = "Hello, world!"; option.font = QFont("Arial", 14); option.palette.setColor(QPalette::Text, QColor(255, 0, 0)); QRect rect = QStyle::visualRect(option.direction, option.rect, QRect(0, 0, 100, 100)); p->save(); p->translate(rect.topLeft()); style()->drawItemText(p, rect, Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, option.text, QPalette::Text); p->restore();
QRect rect = QRect(0, 0, 100, 100); style()->drawItemText(p, rect, Qt::AlignCenter, option.palette, true, "Hello, world!");
QRect rect = QRect(0, 0, 100, 100); style()->drawItemText(p, rect, Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, "This is a long string that is too big to fit in the rectangle", QPalette::Text, &rect);This example draws a long string that is too big to fit within the specified rectangle. An ellipsis is automatically added to the end of the text to indicate that it has been truncated. All of these examples use functions from the Qt package library, which is a comprehensive set of tools and utilities for developing cross-platform applications in C++.