オブジェクトに数字を描画しようとしていQRubberBand
ます。QRubberBand
オブジェクトを持つクラス ウィジェットがありますrectangleRubberBand
。
この領域などを表示することはできますが、この領域の幅や高さなど、ウィジェットではなく領域に描画しようとしています。これどうやってするの?チャートの測定用です。
オブジェクトに数字を描画しようとしていQRubberBand
ます。QRubberBand
オブジェクトを持つクラス ウィジェットがありますrectangleRubberBand
。
この領域などを表示することはできますが、この領域の幅や高さなど、ウィジェットではなく領域に描画しようとしています。これどうやってするの?チャートの測定用です。
輪ゴムで描いているわけではありませんが、必要なことはしています:
void MyButton::mouseMoveEvent(QMouseEvent *event)
{
rubberBand->setGeometry(QRect(mypoint, event->pos()).normalized());//Area Bounding
QToolTip::showText( event->globalPos(), QString("%1,%2")
.arg(rubberBand->size().width())
.arg(rubberBand->size().height()),this );
}
QToolTip
カーソル付近に表示されます。動的に変化し、輪ゴムのサイズに関する実際の情報を表示します。
結果(黒い部分がカーソル):
難しい解決策: サブクラス化QRubberBand
と再実装paintEvent
。例えば:
ヘッダー:
#ifndef RUBBERBAND_H
#define RUBBERBAND_H
#include <QRubberBand>
#include <QPaintEvent>
class RubberBand : public QRubberBand
{
Q_OBJECT
public:
explicit RubberBand(Shape s, QWidget * p = 0);
signals:
protected:
void paintEvent(QPaintEvent *event);
public slots:
};
#endif // RUBBERBAND_H
cpp :
#include "rubberband.h"
#include <QPainter>
RubberBand::RubberBand(QRubberBand::Shape s, QWidget *p) :
QRubberBand(s,p)
{
}
void RubberBand::paintEvent(QPaintEvent *event)
{
QRubberBand::paintEvent(event);
QPainter p(this);
p.setPen(QPen(Qt::black,2));
if(size().width() >10 && size().height() >10)
{
p.drawText(20,20,QString("%1,%2").arg(size().width()).arg(size().height()));
}
}
結果:
最適なアプローチを選択してください。