Results 1 to 5 of 5

Thread: The Creation of Balloon Message Problem

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2009
    Posts
    15
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows

    Default The Creation of Balloon Message Problem

    Hi all,

    I want to make a class of balloon message. I’ve added the code below. But both the position of balloon within the widget and the size of widget is wrong. The shape of JBalloonTip is always rectangle not a balloon; Where does the problem arise from?

    #define JBALLOON_WIDTH 200
    #define JBALLOON_HEIGHT 100

    class JBalloonTip : public QWidget
    {
    Q_OBJECT

    public:
    JBalloonTip();
    ~JBalloonTip();

    void showBalloon(QPoint globalPos, QPoint localPos);
    protected:
    void timerEvent(QTimerEvent *e);
    void paintEvent(QPaintEvent *);
    void resizeEvent(QResizeEvent *);
    private:
    QPainterPath mBalloonPath;
    };
    JBalloonTip::JBalloonTip() :
    QWidget(0, Qt::ToolTip | Qt::FramelessWindowHint)
    {
    }

    JBalloonTip::~JBalloonTip()
    {
    }

    void JBalloonTip::timerEvent(QTimerEvent *e)
    {
    int timerId = e->timerId();
    killTimer(timerId);
    close();

    QWidget::timerEvent(e);
    }

    void JBalloonTip::showBalloon(QPoint globalPos, QPoint localPos)
    {
    int leftWidth = (JBALLOON_WIDTH / 5);
    int xTopLeft = globalPos.x() - leftWidth;
    int yTopLeft = globalPos.y() - JBALLOON_HEIGHT;
    int arrowWidth = (leftWidth / 2);
    int rightWidth = JBALLOON_WIDTH - (leftWidth + arrowWidth);

    QPoint topLeftPoint(xTopLeft, yTopLeft);
    QPoint nextPoint = globalPos;

    mBalloonPath.moveTo(globalPos);

    // STEP 1
    nextPoint.rx() += arrowWidth;
    nextPoint.ry() -= arrowWidth;
    mBalloonPath.lineTo(nextPoint);

    // STEP 2
    nextPoint.rx() += rightWidth;
    mBalloonPath.lineTo(nextPoint);

    // STEP 3.
    int leftHeight = JBALLOON_HEIGHT - arrowWidth;
    nextPoint.ry() -= leftHeight;
    mBalloonPath.lineTo(nextPoint);

    // STEP 4.
    nextPoint = topLeftPoint;
    mBalloonPath.lineTo(nextPoint);

    // STEP 5.
    nextPoint.ry() += leftHeight;
    mBalloonPath.lineTo(nextPoint);

    // STEP 6.
    nextPoint.rx() += leftWidth;
    mBalloonPath.lineTo(nextPoint);

    // STEP 7.
    nextPoint.setY(globalPos.y());
    mBalloonPath.lineTo(nextPoint);

    mBalloonPath.closeSubpath();

    this->move(topLeftPoint);

    startTimer(1000);
    this->show();
    }

    void JBalloonTip::resizeEvent(QResizeEvent *)
    {
    // Set the mask
    QBitmap bitmap = QBitmap(sizeHint());
    bitmap.fill(Qt::color0);
    QPainter painter1(&bitmap);
    painter1.setPen(QPen(Qt::color1, 1));
    painter1.setBrush(QBrush(Qt::color1));
    painter1.drawPath(mBalloonPath);

    this->setMask(bitmap);
    }

    void JBalloonTip:aintEvent(QPaintEvent *)
    {
    QPainter p(this);
    p.drawPath(mBalloonPath);

    }
    I've attached the view of JBalloonTip.

    jballoontip.png

    Thanks advance for your helps and clarifications,
    Attached Images Attached Images

Similar Threads

  1. Replies: 3
    Last Post: 18th July 2010, 13:53
  2. Table Creation Problem.
    By damodharan in forum Qt Programming
    Replies: 4
    Last Post: 3rd June 2010, 12:11
  3. balloon message in Qt
    By wagmare in forum Qt Programming
    Replies: 5
    Last Post: 26th March 2009, 16:37
  4. how can I make a balloon to wrap the editable text?
    By learning_qt in forum Qt Programming
    Replies: 9
    Last Post: 20th January 2009, 15:09
  5. QSystemTrayIcon: Overridden balloon msg
    By further in forum Qt Programming
    Replies: 2
    Last Post: 17th April 2008, 10:58

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.