void CPPageExternalFilters::OnDropFiles(CAtlList<CString>& slFiles, DROPEFFECT) { SetActiveWindow(); POSITION pos = slFiles.GetHeadPosition(); while (pos) { CString fn = slFiles.GetNext(pos); CFilterMapper2 fm2(false); fm2.Register(fn); while (!fm2.m_filters.IsEmpty()) { if (FilterOverride* f = fm2.m_filters.RemoveHead()) { CAutoPtr<FilterOverride> p(f); int i = m_filters.AddString(f->name); m_filters.SetItemDataPtr(i, m_pFilters.AddTail(p)); m_filters.SetCheck(i, 1); if (fm2.m_filters.IsEmpty()) { m_filters.SetCurSel(i); OnFilterSelectionChange(); } SetModified(); } } } }
void tst_QFontMetrics::same() { QFont font; font.setBold(true); QFontMetrics fm(font); const QString text = QLatin1String("Some stupid STRING"); QCOMPARE(fm.size(0, text), fm.size(0, text)) ; for (int i = 10; i <= 32; ++i) { font.setPixelSize(i); QFontMetrics fm1(font); QCOMPARE(fm1.size(0, text), fm1.size(0, text)); } { QImage image; QFontMetrics fm2(font, &image); QString text2 = QLatin1String("Foo Foo"); QCOMPARE(fm2.size(0, text2), fm2.size(0, text2)); //used to crash } { QImage image; QFontMetricsF fm3(font, &image); QString text2 = QLatin1String("Foo Foo"); QCOMPARE(fm3.size(0, text2), fm3.size(0, text2)); //used to crash } }
void CPPageExternalFilters::OnDropFiles(CAtlList<CString>& slFiles, DROPEFFECT) { SetActiveWindow(); POSITION pos = slFiles.GetHeadPosition(); while (pos) { CString fn = slFiles.GetNext(pos); CFilterMapper2 fm2(false); fm2.Register(fn); while (!fm2.m_filters.IsEmpty()) { if (FilterOverride* f = fm2.m_filters.RemoveHead()) { CAutoPtr<FilterOverride> p(f); int i = m_filters.InsertItem(m_filters.GetItemCount(), f->name); m_filters.SetItemData(i, reinterpret_cast<DWORD_PTR>(m_pFilters.AddTail(p))); m_filters.SetCheck(i, 1); if (fm2.m_filters.IsEmpty()) { m_filters.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED); m_filters.SetSelectionMark(i); OnFilterSelectionChange(); } m_filters.SetColumnWidth(0, LVSCW_AUTOSIZE); SetModified(); } } } }
void CPPageExternalFilters::OnDropFiles(HDROP hDropInfo) { SetActiveWindow(); UINT nFiles = ::DragQueryFile(hDropInfo, (UINT)-1, NULL, 0); for (UINT iFile = 0; iFile < nFiles; iFile++) { TCHAR szFileName[_MAX_PATH]; ::DragQueryFile(hDropInfo, iFile, szFileName, _MAX_PATH); CFilterMapper2 fm2(false); fm2.Register(szFileName); while (!fm2.m_filters.IsEmpty()) { if (FilterOverride* f = fm2.m_filters.RemoveHead()) { CAutoPtr<FilterOverride> p(f); int i = m_filters.AddString(f->name); m_filters.SetItemDataPtr(i, m_pFilters.AddTail(p)); m_filters.SetCheck(i, 1); if (fm2.m_filters.IsEmpty()) { m_filters.SetCurSel(i); OnLbnSelchangeList1(); } SetModified(); } } } ::DragFinish(hDropInfo); }
void CQPropertyDelegate:: drawFont(QPainter *painter, const QStyleOptionViewItem &option, const QFont &f, const QModelIndex &index) const { QItemDelegate::drawBackground(painter, option, index); QRect rect = option.rect; rect.setWidth(option.rect.height()); rect.adjust(0, 1, -3, -2); QFont f1 = f; QFont f2 = painter->font(); QFontMetrics fm1(f1); QFontMetrics fm2(f2); int fw = fm1.width("Abc"); int fh = fm1.height(); if (fh > rect.height()) { f1.setPixelSize(rect.height()); fm1 = QFontMetrics(f1); fw = fm1.width("Abc"); } int x1 = rect.left(); int y1 = rect.top() + fm1.ascent(); painter->save(); painter->setFont(f1); painter->setPen(QColor(0,0,0)); painter->drawText(x1, y1, "Abc"); painter->restore(); int x2 = x1 + fw + 4; //int y2 = rect.top() + fm2.ascent(); QRect rect1; rect1.setCoords(x2, option.rect.top(), option.rect.right(), option.rect.bottom()); //painter->drawText(x2, y2, f.toString()); QItemDelegate::drawDisplay(painter, option, rect1, f.toString()); }
void UBGraphicsProtractor::paintAngleMarker(QPainter *painter) { painter->save(); painter->translate(rect().center()); painter->rotate(-mStartAngle); painter->translate(-rect().center().x(), -rect().center().y()); qreal co = cos(mCurrentAngle * PI/180); qreal si = sin(mCurrentAngle * PI/180); qreal rad = radius(); painter->drawLine(QLineF(rect().center(), QPointF(rect().center().x()+ (rad+ 20)*co, rect().center().y() - (rad + 20)*si))); QPointF center = rect().center(); painter->drawArc(QRectF(center.x() - rad/8, center.y() - rad/8, rad / 4, rad / 4), 0 , (mCurrentAngle - (int)(mCurrentAngle/360)*360)*16); painter->translate(rect().center()); painter->rotate(-mCurrentAngle); painter->translate(-rect().center().x(), -rect().center().y()); //Paint Angle text (horizontally) //restore transformations painter->translate(rect().center()); painter->rotate(mCurrentAngle); painter->rotate(mStartAngle); painter->translate(-rect().center().x(), -rect().center().y()); qreal angle = mCurrentAngle - (int)(mCurrentAngle/360)*360; if (angle != 0) { QString ang = QString("%1°").arg(angle,0, 'f', 1); QFont font2 = painter->font(); font2.setBold(true); QFontMetricsF fm2(font2); painter->setFont(font2); if (angle < 50) angle = 90; else angle = angle / 2; co = cos((mStartAngle + angle) * PI/180); si = sin((mStartAngle + angle) * PI/180); painter->drawText(QRectF(rect().center().x() + (rad*2.5/10)*co - fm2.width(ang)/2, rect().center().y() - (rad*2.5/10)*si - fm2.height()/2, fm2.width(ang), fm2.height()), Qt::AlignTop, ang); } painter->restore(); }
QSize ItemDelegate::sizeHint (const QStyleOptionViewItem &option, const QModelIndex &index) const { if (!index.isValid()) return QSize(); QFont normalfont = option.font; QFont boldfont = normalfont; boldfont.setBold(true); // Extract the items we want to measure QString firstRow = firstLine(index); QString secondRow = secondLine(index); // Compute the height QFontMetrics fm1(boldfont); QFontMetrics fm2(normalfont); int height = fm1.lineSpacing() + fm2.lineSpacing(); height = qMax(height, option.decorationSize.height()); // Compute the text width int width = fm1.width(firstRow); width = qMax(width, fm2.width(secondRow)); // Add decoration width + margin width += option.decorationSize.width()+decorationMargin; return QSize(width, height+16); }
void ArtistListItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QString artistName = index.data(Qt::DisplayRole).toString(); QString albumSongCount; albumSongCount.append(tr("%n album(s)", "", index.data(UserRoleAlbumCount).toInt())); albumSongCount.append(", "); albumSongCount.append(tr("%n song(s)", "", index.data(UserRoleSongCount).toInt())); painter->save(); QRect r = option.rect; if (option.state & QStyle::State_Selected) QStyledItemDelegate::paint(painter, option, QModelIndex()); QColor secondaryColor = QMaemo5Style::standardColor("SecondaryTextColor"); painter->drawPixmap(r.right()-70+3, r.top()+3, 64, 64, qvariant_cast<QIcon>(index.data(Qt::DecorationRole)).pixmap(64)); int textWidth = r.width() - (15+70+15); QFont f = painter->font(); f.setPointSize(18); painter->setFont(f); QFontMetrics fm1(f); artistName = fm1.elidedText(artistName, Qt::ElideRight, textWidth); painter->drawText(15, r.top()+5, textWidth, r.height(), Qt::AlignTop|Qt::AlignLeft, artistName); r.setBottom(r.bottom()-10); f.setPointSize(13); painter->setFont(f); painter->setPen(QPen(secondaryColor)); QFontMetrics fm2(f); artistName = fm2.elidedText(albumSongCount, Qt::ElideRight, textWidth); painter->drawText(15, r.top(), textWidth, r.height(), Qt::AlignBottom|Qt::AlignLeft, albumSongCount); painter->restore(); }
Int_t main(Int_t argc, Char_t *argv[]) { ROOT::Mpi::TEnvironment env(argc, argv); ROOT::Mpi::TIntraCommunicator world; // MpiInitTest(world, 2, ROOT::Mpi::GreaterIqual); TMatrixT<Double_t> mResult; TMatrixT<Double_t> m1(rowm1, colm1); TMatrixT<Double_t> m2(rowm2, colm2); TMatrixT<Double_t> m1square(side, side); TMatrixT<Double_t> m2square(side, side); for (Int_t i = 0; i < rowm1; i++) for (Int_t j = 0; j < colm1; j++) m1[i][j] = i + j; for (Int_t i = 0; i < rowm2; i++) for (Int_t j = 0; j < colm2; j++) m2[i][j] = j; for (Int_t i = 0; i < side; i++) for (Int_t j = 0; j < side; j++) { m1square[i][j] = j; m2square[i][j] = i; } /////////////////////////////////////////////// //Testing methdos with results in single Rank// /////////////////////////////////////////////// ROOT::Mpi::Math::TMatrixTWrapper<Double_t> mul(m1); mul.Mult(m2, root); ROOT::Mpi::Math::TMatrixTWrapper<Double_t> add(m1square); add.Addition(m2square, root); ROOT::Mpi::Math::TMatrixTWrapper<Double_t> sub(m1square); sub.Subtraction(m2square, root); ROOT::Mpi::Math::TMatrixTWrapper<Double_t> trans(m2); trans.Transpose(root); if (world.Rank() == root) { mul.GetResult(mResult); MpiCompareTMatrixTest(mResult, m1 * m2, world.Rank(), "Matrix Multiplication Single"); add.GetResult(mResult); MpiCompareTMatrixTest(mResult, m1square + m2square, world.Rank(), "Matrix Addition Single"); sub.GetResult(mResult); MpiCompareTMatrixTest(mResult, m1square - m2square, world.Rank(), "Matrix Subtraction Single"); trans.GetResult(mResult); MpiCompareTMatrixTest(mResult, TMatrixT<Double_t>(m2.GetNcols(), m2.GetNrows()).Transpose(m2), world.Rank(), "Matrix Transpose Single"); } /////////////////////////////////////////////// //Testing methdos with results in all ranks // /////////////////////////////////////////////// ROOT::Mpi::Math::TMatrixTWrapper<Double_t> mulAll(m1);//return the results in all ranks mulAll.Mult(m2); mulAll.GetResult(mResult); MpiCompareTMatrixTest(mResult, m1 * m2, world.Rank(), "Matrix Multiplication All"); ROOT::Mpi::Math::TMatrixTWrapper<Double_t> addAll(m1square); addAll.Addition(m2square); ROOT::Mpi::Math::TMatrixTWrapper<Double_t> subAll(m1square); subAll.Subtraction(m2square); ROOT::Mpi::Math::TMatrixTWrapper<Double_t> transAll(m2); transAll.Transpose(); addAll.GetResult(mResult); MpiCompareTMatrixTest(mResult, m1square + m2square, world.Rank(), "Matrix Addition All"); subAll.GetResult(mResult); MpiCompareTMatrixTest(mResult, m1square - m2square, world.Rank(), "Matrix Subtraction All"); transAll.GetResult(mResult); MpiCompareTMatrixTest(mResult, TMatrixT<Double_t>(m2.GetNcols(), m2.GetNrows()).Transpose(m2), world.Rank(), "Matrix Transpose All"); ////////////////////////////////////////////////// //Testing methdos with multiple matrices types // ////////////////////////////////////////////////// THilbertMatrixT<Double_t> him(side, side); TMatrixTSparse<Double_t> sm1(rowm1, colm1); TMatrixTSparse<Double_t> sm2(rowm2, colm2); TMatrixTFlat<Double_t> fm1(m1); TMatrixTFlat<Double_t> fm2(m2); TMatrixTSparse<Double_t> smResult; for (Int_t i = 0; i < rowm1; i++) for (Int_t j = 0; j < colm1; j++) { sm1[i][j] = i * j; } for (Int_t i = 0; i < rowm2; i++) for (Int_t j = 0; j < colm2; j++) { sm2[i][j] = i * j; } ROOT::Mpi::Math::TMatrixTWrapper<Double_t> mulHim(m1square);//return the results in all ranks mulHim.Mult(him); mulHim.GetResult(mResult); MpiCompareTMatrixTest(mResult, m1square * TMatrixT<Double_t>(him), world.Rank(), "Matrix Multiplication HilbertMatrix"); ROOT::Mpi::Math::TMatrixTWrapper<Double_t> mulHim2(him);//return the results in all ranks mulHim2.Mult(m1square); mulHim2.GetResult(mResult); MpiCompareTMatrixTest(mResult, TMatrixT<Double_t>(him)*m1square, world.Rank(), "Matrix Multiplication HilbertMatrix In Constructor"); ROOT::Mpi::Math::TMatrixTWrapper<Double_t> mulSm(m1);//return the results in all ranks mulSm.Mult(sm2); mulSm.GetResult(smResult); MpiCompareTMatrixTest(smResult, m1 * sm2, world.Rank(), "Matrix Multiplication SparseMatrix"); ROOT::Mpi::Math::TMatrixTWrapper<Double_t> mulSm2(sm1);//return the results in all ranks mulSm2.Mult(m2); mulSm2.GetResult(smResult); MpiCompareTMatrixTest(smResult, sm1 * m2, world.Rank(), "Matrix Multiplication SparseMatrix In Constructor"); // ROOT::Mpi::Math::TMatrixTWrapper<Double_t> mulFm(m1);//return the results in all ranks mulFm.Mult(fm2); mulFm.GetResult(mResult); MpiCompareTMatrixTest(mResult, m1 * TMatrixT<Double_t>(fm2.GetMatrix()->GetNrows(), fm2.GetMatrix()->GetNcols(), fm2.GetMatrix()->GetMatrixArray()), world.Rank(), "Matrix Multiplication FlatMatrix"); ROOT::Mpi::Math::TMatrixTWrapper<Double_t> mulFm2(fm1);//return the results in all ranks mulFm2.Mult(m2); mulFm2.GetResult(mResult); //NOTE fm matrix have data from m2, is the same tell m1*m2, just change the representation in memory MpiCompareTMatrixTest(mResult, m1 * m2, world.Rank(), "Matrix Multiplication FlatMatrix In Constructor"); TVectorT<Double_t> vec(rowv); for (Int_t i = 0; i < rowv; i++) vec[i] = i; ROOT::Mpi::Math::TMatrixTWrapper<Double_t> mulVec(m1);//return the results in all ranks mulVec.Mult(vec); mulVec.GetResult(mResult); TMatrixT<Double_t> mr((m1 * vec).GetNrows(), 1, (m1 * vec).GetMatrixArray()); // mResult.Print(); // mr.Print(); MpiCompareTMatrixTest(mResult, mr, world.Rank(), "Matrix Multiplication with Vector"); return 0; }
void span(const i64 single, const i64 nused, const i64 maxsofar, const i64 max, i64& mfinal, const vector<i64> flags, const vector<i64> flagm, const vector<i64> mult){ for(unsigned int i= 0; i < mult.size(); ++i){ i64 value = mult[i]; while(value){ int res = value % 10; assert(flagm[res]==1); value /= 10; } } if(nused == 10){ if(maxsofar < max) return; vector<i64> fm2(flagm); i64 vm2 = maxsofar*single; while(vm2){ i64 res = vm2 % 10; vm2 /= 10; if(fm2[res] == 0){ fm2[res] = 1; }else{ return; } } vm2 = maxsofar*single; vector<i64> m2(mult); m2.push_back(vm2); i64 tresult = 0; while(!m2.empty()){ for(unsigned int j = 0; j< m2.size()-1; ++j){ if(firstdig(m2[j], m2.back())){ swap(m2.back(), m2[j]); } } i64 cv = m2.back(); i64 order = 1; while(cv){ order *= 10; cv/=10; } cv = m2.back(); tresult = tresult * order + cv ; m2.pop_back(); } if(tresult > mfinal){ mfinal = tresult; for(unsigned int i = 0; i < mult.size();++i) printf("%lld ", mult[i]); printf("%lld \n", vm2); printf("%lld\n", mfinal); } return; } for( i64 i = 0; i< static_cast<int>(flags.size()); ++i){ if(flags[i]) continue; //if(maxsofar == 0 && i == 0) continue; vector<i64> f2(flags); f2[i] = 1; i64 mfar2 = maxsofar*10+ i; span(single, nused +1, mfar2, max, mfinal, f2, flagm, mult); if(mfar2 > max) { i64 vm2 = mfar2*single; bool nooverlap = true; vector<i64> fm2(flagm); while(vm2){ i64 res = vm2 % 10; vm2 /= 10; if(fm2[res] == 0){ fm2[res] = 1; }else{ nooverlap = false; break; } } if(nooverlap){ vector<i64> m2(mult); vm2 = mfar2*single; m2.push_back(vm2); span(single, nused +1, 0, mfar2, mfinal, f2, fm2, m2); } } } }
void UBGraphicsProtractor::paintGraduations(QPainter *painter) { painter->save(); const int tenDegreeGraduationLength = 15; const int fiveDegreeGraduationLength = 10; const int oneDegreeGraduationLength = 5; QFont font1 = painter->font(); #ifdef Q_WS_MAC font1.setPointSizeF(font1.pointSizeF() - 3); #endif QFontMetricsF fm1(font1); //Font for internal arc QFont font2 = painter->font(); font2.setPointSizeF(font1.pointSizeF()/1.5); QFontMetricsF fm2(font2); qreal rad = radius(); QPointF center = rect().center(); painter->drawArc(QRectF(center.x() - rad/2, center.y() - rad/2, rad, rad), mStartAngle*16, mSpan*16); for (int angle = 1; angle < mSpan; angle++) { int graduationLength = (0 == angle % 10) ? tenDegreeGraduationLength : ((0 == angle % 5) ? fiveDegreeGraduationLength : oneDegreeGraduationLength); qreal co = cos(((qreal)angle + mStartAngle) * PI/180); qreal si = sin(((qreal)angle + mStartAngle) * PI/180); if (0 == angle % 90) painter->drawLine(QLineF(QPointF(center.x(), center.y()), QPointF(center.x() + co*tenDegreeGraduationLength, center.y() - si*tenDegreeGraduationLength))); //external arc painter->drawLine(QLineF(QPointF(center.x()+ rad*co, center.y() - rad*si), QPointF(center.x()+ (rad - graduationLength)*co, center.y() - (rad - graduationLength)*si))); //internal arc painter->drawLine(QLineF(QPointF(center.x()+ rad/2*co, center.y() - rad/2*si), QPointF(center.x()+ (rad/2 + graduationLength)*co, center.y() - (rad/2 + graduationLength)*si))); if (0 == angle % 10) { //external arc painter->setFont(font1); QString grad = QString("%1").arg((int)(angle)); QString grad2 = QString("%1").arg((int)(mSpan - angle)); painter->drawText(QRectF(center.x() + (rad - graduationLength*1.5)*co - fm1.width(grad)/2, center.y() - (rad - graduationLength*1.5)*si - fm1.height()/2, fm1.width(grad), fm1.height()), Qt::AlignTop, grad); //internal arc painter->setFont(font2); painter->drawText(QRectF(center.x() + (rad/2 + graduationLength*1.5)*co - fm2.width(grad2)/2, center.y() - (rad/2 + graduationLength*1.5)*si - fm2.height()/2, fm2.width(grad2), fm2.height()), Qt::AlignTop, grad2); painter->setFont(font1); } } painter->restore(); }
void BehavePlusApp::drawSplashPage( void ) { // If unable to load the picture, make a plain cyan backdrop instead if ( m_pixmap.isNull() ) // This code block should never be executed! { m_pixmap.resize( 700, 500 ); QPainter paint( &m_pixmap ); paint.fillRect( 0, 0, 700, 500, QBrush( "cyan", SolidPattern ) ); paint.end(); } // Painter attributes int align = Qt::AlignHCenter | Qt::AlignTop ; //static QString fontName( "Times New Roman" ); static QString fontName( "Arial" ); QFont fnt1( fontName, 48, QFont::Bold, false ); QFont fnt2( fontName, 24, QFont::Bold, false ); QFont fnt3( fontName, 16, QFont::Bold, false ); QFontMetrics fm1( fnt1 ); QFontMetrics fm2( fnt2 ); QFontMetrics fm3( fnt3 ); QPen blackPen( black ); QPen grayPen( gray ); QPen redPen( red ); QPen whitePen( white ); // Draw shadowed name QPainter paint( &m_pixmap ); int wd = m_pixmap.width(); int ht = m_pixmap.height() + 3 * fm3.lineSpacing(); paint.setFont( fnt1 ); paint.setPen( grayPen ); int y0 = fm1.lineSpacing()/8; paint.drawText( 4, y0+4, wd, ht, align, m_program ); paint.setPen( blackPen ); paint.drawText( 2, y0+2, wd, ht, align, m_program ); paint.setPen( whitePen ); paint.drawText( 0, y0, wd, ht, align, m_program ); // Draw sub name and version y0 += 3*fm1.lineSpacing()/4; paint.setFont( fnt2 ); paint.drawText( 0, y0, wd, ht-y0, align, "fire modeling system" ); y0 += 3*fm2.lineSpacing()/4; paint.drawText( 0, y0, wd, ht-y0, align, "Version " + m_version ); // Warning if ( ShowWarning ) { y0 += 3 * fm2.lineSpacing(); paint.setFont( fnt2 ); paint.setPen( redPen ); paint.drawText( 0, y0, wd, ht-y0, align, "This is pre-release software" ); y0 += fm2.lineSpacing(); paint.drawText( 0, y0, wd, ht-y0, align, "for testing purposes only!" ); y0 += fm2.lineSpacing(); paint.drawText( 0, y0, wd, ht-y0, align, "Use at Your Own Risk!" ); } // Authors y0 = ht - 6 * fm3.lineSpacing(); paint.setFont( fnt3 ); paint.setPen( whitePen ); paint.drawText( 0, y0, wd, ht-y0, align, "US Forest Service, Rocky Mountain Research Station" ); y0 += fm3.lineSpacing(); paint.drawText( 0, y0, wd, ht-y0, align, "& Systems for Environmental Management" ); paint.end(); // Status message display area m_statusLine = ht - 2 * fm3.lineSpacing(); return; }
void AMSamplePlatePre2013ItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QString sampleName(index.data(Qt::DisplayRole).toString()); QString elementString(index.data(AM::UserRole).toString()); if(!elementString.isEmpty()) { elementString.prepend("("); elementString.append(")"); } QString createdString(index.data(AM::DescriptionRole).toString()); QString positionsString(index.data(AM::UserRole+1).toString()); if(positionsString.isEmpty()) { positionsString = "[Unknown sample position]"; } QStyleOptionViewItemV4 opt(option); initStyleOption(&opt, index); QStyle* sty = QApplication::style(); // Draw the background: (this will handle selection for us. You can also probe selection directly with opt.state & QStyle::State_Selected) sty->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter); int textStartingPoint = 0; // Do we have a pixmap available? QRect iconRect = opt.rect; iconRect.adjust(6, 0, 0, 0); if(opt.features & QStyleOptionViewItemV4::HasDecoration) { QPixmap p = opt.icon.pixmap(opt.decorationSize); sty->drawItemPixmap(painter, iconRect, Qt::AlignLeft | Qt::AlignVCenter, p); textStartingPoint += 6 + p.width() + 6; } // textRect starts 6px from the edge of the decoration, and is inset 6px on top and bottom and right. It's the full room we have available for text. QRect textRect = opt.rect; textRect.adjust( textStartingPoint, 6, -6, -6); QFont font = opt.font; font.setPointSize(font.pointSize()+4); painter->setFont(font); painter->setPen(opt.palette.text().color()); QRect actualNameTextRect; painter->drawText(textRect, Qt::AlignLeft | Qt::AlignTop, sampleName, &actualNameTextRect); // Move over by the amount that we filled with text QRect elementTextRect(actualNameTextRect.right() + 6, textRect.top(), textRect.width()-actualNameTextRect.width() - 6, actualNameTextRect.height()); font.setPointSize(font.pointSize()-4); font.setItalic(true); font.setBold(true); painter->setFont(font); painter->setPen(Qt::darkGray); QFontMetrics fm(font); QString elidedElements = fm.elidedText(elementString, Qt::ElideRight, elementTextRect.width()); painter->drawText(elementTextRect, Qt::AlignLeft | Qt::AlignBottom, elidedElements); QRect descriptionTextRect(textRect.left(), actualNameTextRect.bottom(), textRect.width(), textRect.height()-actualNameTextRect.height()); font.setPointSize(font.pointSize()-2); font.setItalic(false); font.setBold(false); painter->setFont(font); painter->setPen(Qt::darkGray); painter->drawText(descriptionTextRect, Qt::AlignLeft | Qt::AlignTop, createdString); QFontMetrics fm2(font); QRect actualPositionsTextRect; painter->drawText(textRect, Qt::AlignLeft | Qt::AlignBottom, fm2.elidedText(positionsString, Qt::ElideMiddle, textRect.width()), &actualPositionsTextRect); int dividerLineY = actualPositionsTextRect.top() - 4; painter->drawLine(QPoint(textRect.left(), dividerLineY), QPoint(textRect.right(), dividerLineY)); }