예제 #1
0
		int paintVerticalCell
			(QPainter *painter,
			 const QHeaderView* hv,
			 const QModelIndex& cellIndex,
			 const QModelIndex& leafIndex,
			 int logicalLeafIndex,
			 const QStyleOptionHeader& styleOptions,
			 const QRect& sectionRect,
			 int left) const
		{
			QStyleOptionHeader uniopt(styleOptions);
			setForegroundBrush(uniopt, cellIndex);
			setBackgroundBrush(uniopt, cellIndex);

			int width=cellSize(cellIndex, hv, uniopt).width();
			if(cellIndex==leafIndex)
				width=sectionRect.width()-left;
			int top=currentCellLeft(cellIndex, leafIndex, logicalLeafIndex, sectionRect.top(), hv);
			int height=currentCellWidth(cellIndex, leafIndex, logicalLeafIndex, hv);

			QRect r(left, top, width, height);

			uniopt.text = cellIndex.data(Qt::DisplayRole).toString();

			if(cellIndex.data(Qt::UserRole).isValid())
			{
				QRect new_r(0, 0,  r.width(), r.height());
				uniopt.rect = new_r;
				QPixmap original_button(r.width(), r.height());
				QPainter original_button_painter(&original_button);
				hv->style()->drawControl(QStyle::CE_HeaderSection, &uniopt, &original_button_painter, hv);

				new_r.setWidth(r.height());
				new_r.setHeight(r.width());
				QMatrix m;
				m.translate(0, r.height());
				m.rotate(-90);
				original_button_painter.setWorldMatrix(m, true);
				uniopt.rect = new_r;
				hv->style()->drawControl(QStyle::CE_HeaderLabel, &uniopt, &original_button_painter, hv);

				painter->drawPixmap(r, original_button);
			}
			else
			{
				bool clipping=painter->hasClipping();
				uniopt.rect = r;
				hv->style()->drawControl(QStyle::CE_Header, &uniopt, painter, hv);
				painter->setClipping(clipping);
			}
			return left+width;
		}
    int paintHorizontalCell
        (QPainter *painter,
         const QHeaderView* hv,
         const QModelIndex& cellIndex,
         const QModelIndex& leafIndex,
         int logicalLeafIndex,
         const QStyleOptionHeader& styleOptions,
         const QRect& sectionRect,
         int top) const
    {
        QStyleOptionHeader uniopt(styleOptions);
        setForegroundBrush(uniopt, cellIndex);
        setBackgroundBrush(uniopt, cellIndex);

        int height=cellSize(cellIndex, hv, uniopt).height();
        if(cellIndex==leafIndex)
            height=sectionRect.height()-top;
        int left=currentCellLeft(cellIndex, leafIndex, logicalLeafIndex, sectionRect.left(), hv);
        int width=currentCellWidth(cellIndex, leafIndex, logicalLeafIndex, hv);

        QRect r(left, top, width, height);

        uniopt.text = cellIndex.data(Qt::DisplayRole).toString();

        painter->save();
        uniopt.rect = r;
        if(cellIndex.data(Qt::UserRole).isValid())
        {
            hv->style()->drawControl(QStyle::CE_HeaderSection, &uniopt, painter, hv);
            QMatrix m;
            m.rotate(-90);
            painter->setWorldMatrix(m, true);
            QRect new_r(0, 0,  r.height(), r.width());
            new_r.moveCenter(QPoint(-r.center().y(), r.center().x()));
            uniopt.rect = new_r;
            hv->style()->drawControl(QStyle::CE_HeaderLabel, &uniopt, painter, hv);
        }
        else
        {
            hv->style()->drawControl(QStyle::CE_Header, &uniopt, painter, hv);
        }
        painter->restore();
        hv->childAt(QPoint(uniopt.rect.left()+5, uniopt.rect.top()+3))->setToolTip(uniopt.text);
        return top+height;
    }