Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. The Creation of Balloon Message Problem
QtWS25 Last Chance

The Creation of Balloon Message Problem

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 2.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    yaseminyilmaz
    wrote on 30 Jan 2013, 12:08 last edited by
    #1

    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::paintEvent(QPaintEvent *)
    {
    QPainter p(this);
    p.drawPath(mBalloonPath);

    }
    @

    Thanks advance for your helps and clarifications,

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tzander
      wrote on 30 Jan 2013, 12:22 last edited by
      #2

      The problem is because you are using widgets, and widgets by definition are always square.

      We have been putting a lot of effort in this things called QML, you might like it since this kind of task takes no more than half an hour to complete.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on 30 Jan 2013, 12:28 last edited by
        #3

        Widgets can be make to look like they are "not square":/doc/qt-4.8/widgets-shapedclock.html though.

        1 Reply Last reply
        0

        1/3

        30 Jan 2013, 12:08

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved