Results 1 to 5 of 5

Thread: Help,I want to make a ruler,all the code is here

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2008
    Posts
    41
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Help,I want to make a ruler,all the code is here

    Sorry to my bad english,i want the Rect to fill one color,but it is only a little point.why will
    like that.

    Qt Code:
    1. #include <QApplication>
    2. #include <QWidget>
    3. #include <QPixmap>
    4. #include <QBitmap>
    5. #include <QPoint>
    6. #include <QPalette>
    7. #include <QMouseEvent>
    8. #include <QPainter>
    9.  
    10. class myclass:public QWidget
    11. {
    12. public:
    13. myclass(QWidget *parent = 0);
    14. protected:
    15. void mouseMoveEvent(QMouseEvent *e);
    16. void mousePressEvent(QMouseEvent *e);
    17. private:
    18. QPixmap *pixmap;
    19. QBitmap *bitmap;
    20. QPainter *painter ;
    21. QBrush *brush ;
    22. QPoint last,pos0;
    23. };
    24. myclass::myclass(QWidget *parent)
    25. : QWidget(parent,Qt::X11BypassWindowManagerHint)
    26. {
    27. setGeometry(200,200,800,120);
    28. brush =new QBrush();
    29. brush->setStyle(Qt::SolidPattern) ;
    30. brush->setColor(Qt::gray) ;
    31. pixmap=new QPixmap(800,120);
    32. painter =new QPainter(pixmap) ;
    33.  
    34. //painter->setBackgroundMode(Qt::OpaqueMode);
    35. painter->begin(this) ;
    36. painter->setBackground(*brush) ;
    37. painter->setPen(Qt::red) ;
    38. painter->drawEllipse(10,0,10,10) ;//画了一个小圆圈,运行时可见。
    39. painter->end() ;
    40. QPalette palette;
    41. palette.setBrush(QPalette::Background, QBrush(*pixmap));
    42. setPalette(palette);
    43. setMask(*pixmap);
    44. }
    45. void myclass::mouseMoveEvent(QMouseEvent *e)
    46. {
    47. if (!(e->buttons() & Qt::LeftButton))
    48. return;
    49. QPoint newpos = e->globalPos();
    50. QPoint upleft = pos0 + newpos - last;
    51. move(upleft);
    52. }
    53. void myclass::mousePressEvent(QMouseEvent *e)
    54. {
    55. if (e->button() == Qt::LeftButton)
    56. last = e->globalPos();
    57. pos0 = e->globalPos() - e->pos();
    58. }
    59.  
    60. int main(int argc,char *argv[])
    61. {
    62. QApplication a(argc,argv);
    63. myclass w;
    64. w.showFullScreen();
    65. return a.exec();
    66. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 21st April 2008 at 14:07. Reason: missing [code] tags

Similar Threads

  1. Compiling with Qmake/Make
    By VireX in forum Newbie
    Replies: 25
    Last Post: 22nd February 2007, 05:57
  2. problem with linking
    By mickey in forum Qt Programming
    Replies: 49
    Last Post: 12th August 2006, 21:41

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
  •  
Qt is a trademark of The Qt Company.