Results 1 to 5 of 5

Thread: Inheriting

  1. #1
    Join Date
    Jul 2011
    Posts
    22
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Inheriting

    Hello,
    I want to generate a subclass by extending QDeclarativeMouseArea class.
    In Qt Creator has no intellisense support for sth like:
    Qt Code:
    1. #include <QDeclarativeMouseArea>
    To copy to clipboard, switch view to plain text mode 

    i do not know what to add to pro file, in pro Qt is defined as:
    Qt Code:
    1. QT += core gui declarative
    To copy to clipboard, switch view to plain text mode 

    i could find qdeclarativemouseare_p.h in somewhere under Qt SDK but it is in simulator folder.
    i do not think it can run if i add the path
    Qt Code:
    1. /home/tuxit/QtSDK/Simulator/Qt/gcc/include/QtDeclarative/private
    To copy to clipboard, switch view to plain text mode 

    to INCLUDE in .pro file but still can not be allowed to add

    Qt Code:
    1. #include <QDeclarativeMouseArea>
    To copy to clipboard, switch view to plain text mode 

    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Inheriting

    QDeclarativeMouseArea is not a public Qt class, you can't use it in your code.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    tuxit (12th August 2011)

  4. #3
    Join Date
    Jul 2011
    Posts
    22
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Inheriting

    Thanks for the reply,
    i want to ask
    is it legal to copy its content and use in my own class?

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Inheriting

    It depends on the licence of your program, but even if you do copy it, it won't work just like that. You'd have to copy half of Qt together with it. What do you need the class for?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #5
    Join Date
    Jul 2011
    Posts
    22
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Inheriting

    i have a custom qdeclarativeitem subclass type called polygon
    i want to drag one polygon to another and want other polygon to change its color for example.
    the "other polygon" must know a polygon is dragged enter into it. also when i dragged one polygon it must move, not stay old place.
    i found the codes at the bottom of the post and i write

    Qt Code:
    1. Polygon{
    2. id:poly1
    3. //poly specifications
    4. DragArea{
    5.  
    6.  
    7. }
    8.  
    9. }
    10.  
    11. Polygon{
    12. id:poly2
    13. //poly specifications
    14. DropArea{
    15.  
    16.  
    17. }
    18.  
    19. }
    To copy to clipboard, switch view to plain text mode 

    and when i clicked in poly1 and dragged the mouse into poly2, poly2 become notified

    BUT poly1 stays at its old place, i want it to move.

    so i tried sth like


    Qt Code:
    1. Polygon{
    2. id:poly1
    3. //poly specifications
    4. DragArea{
    5. //some code
    6.  
    7. MouseArea{
    8. //some code
    9. }
    10.  
    11. }
    12.  
    13. }
    14.  
    15. Polygon{
    16. id:poly2
    17. //poly specifications
    18. DropArea{
    19.  
    20.  
    21. }
    22.  
    23. }
    To copy to clipboard, switch view to plain text mode 

    and tried sth more but can not succeed.

    I do not know if i make a dragging by myself, so i want to extend mousearea class and write drag area code in it.
    Thanks for reply

    Codes that i found, DragArea DropAea classes:


    Qt Code:
    1. #include "DeclarativeDragArea.h"
    2. #include "DeclarativeMimeData.h"
    3.  
    4. #include <QDrag>
    5. #include <QMimeData>
    6. #include <QGraphicsSceneMouseEvent>
    7. #include <QApplication>
    8. #include <QGraphicsScene>
    9. #include <QGraphicsView>
    10.  
    11. /*!
    12. A DragArea is used to make an item draggable.
    13. */
    14.  
    15. DeclarativeDragArea::DeclarativeDragArea(QDeclarativeItem *parent)
    16. : QDeclarativeItem(parent),
    17. m_delegate(0),
    18. m_source(0),
    19. m_target(0),
    20. m_enabled(true),
    21. m_supportedActions(Qt::MoveAction),
    22. m_defaultAction(Qt::MoveAction),
    23. m_data(new DeclarativeMimeData()) // m_data is owned by us, and we shouldn't pass it to Qt directly as it will automatically delete it after the drag and drop.
    24. {
    25. setAcceptedMouseButtons(Qt::LeftButton);
    26. }
    27.  
    28. DeclarativeDragArea::~DeclarativeDragArea()
    29. {
    30. if (m_data) {
    31. delete m_data;
    32. }
    33. }
    34.  
    35. /*!
    36.   The delegate is the item that will be displayed next to the mouse cursor during the drag and drop operation.
    37.   It usually consists of a large, semi-transparent icon representing the data being dragged.
    38. */
    39. QDeclarativeComponent* DeclarativeDragArea::delegate() const
    40. {
    41. return m_delegate;
    42. }
    43. void DeclarativeDragArea::setDelegate(QDeclarativeComponent *delegate)
    44. {
    45. if (m_delegate != delegate) {
    46. m_delegate = delegate;
    47. emit delegateChanged();
    48. }
    49. }
    50. void DeclarativeDragArea::resetDelegate()
    51. {
    52. setDelegate(0);
    53. }
    54.  
    55. /*!
    56.   The QML element that is the source of this drag and drop operation. This can be defined to any item, and will
    57.   be available to the DropArea as event.data.source
    58. */
    59. QDeclarativeItem* DeclarativeDragArea::source() const
    60. {
    61. return m_source;
    62. }
    63. void DeclarativeDragArea::setSource(QDeclarativeItem* source)
    64. {
    65. if (m_source != source) {
    66. m_source = source;
    67. emit sourceChanged();
    68. }
    69. }
    70. void DeclarativeDragArea::resetSource()
    71. {
    72. setSource(0);
    73. }
    74.  
    75. // target
    76. QDeclarativeItem* DeclarativeDragArea::target() const
    77. {
    78. //TODO: implement me
    79. return 0;
    80. }
    81.  
    82. // data
    83. DeclarativeMimeData* DeclarativeDragArea::data() const
    84. {
    85. return m_data;
    86. }
    87.  
    88. // enabled
    89. bool DeclarativeDragArea::isEnabled() const
    90. {
    91. return m_enabled;
    92. }
    93. void DeclarativeDragArea::setEnabled(bool enabled)
    94. {
    95. if (enabled != m_enabled) {
    96. m_enabled = enabled;
    97. emit enabledChanged();
    98. }
    99. }
    100.  
    101. // supported actions
    102. Qt::DropActions DeclarativeDragArea::supportedActions() const
    103. {
    104. return m_supportedActions;
    105. }
    106. void DeclarativeDragArea::setSupportedActions(Qt::DropActions actions)
    107. {
    108. if (actions != m_supportedActions) {
    109. m_supportedActions = actions;
    110. emit supportedActionsChanged();
    111. }
    112. }
    113.  
    114. // default action
    115. Qt::DropAction DeclarativeDragArea::defaultAction() const
    116. {
    117. return m_defaultAction;
    118. }
    119. void DeclarativeDragArea::setDefaultAction(Qt::DropAction action)
    120. {
    121. if (action != m_defaultAction) {
    122. m_defaultAction = action;
    123. emit defaultActionChanged();
    124. }
    125. }
    126.  
    127. void DeclarativeDragArea::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
    128. {
    129. if ( !m_enabled
    130. || QLineF(event->screenPos(), event->buttonDownScreenPos(Qt::LeftButton)).length()
    131. < QApplication::startDragDistance()) {
    132. return;
    133. }
    134.  
    135. QDrag *drag = new QDrag(event->widget());
    136. DeclarativeMimeData* dataCopy = new DeclarativeMimeData(m_data); //Qt will take ownership of this copy and delete it.
    137. drag->setMimeData(dataCopy);
    138.  
    139. if (m_delegate) {
    140.  
    141. // Render the delegate to a Pixmap
    142.  
    143. QDeclarativeItem* item = qobject_cast<QDeclarativeItem *>(m_delegate->create());
    144.  
    145. scene.addItem(item);
    146.  
    147. QPixmap pixmap(scene.sceneRect().width(), scene.sceneRect().height());
    148. pixmap.fill(Qt::transparent);
    149.  
    150. QPainter painter(&pixmap);
    151. painter.setRenderHint(QPainter::Antialiasing);
    152. scene.render(&painter);
    153.  
    154. drag->setPixmap(pixmap);
    155. drag->setHotSpot(QPoint(0, 0)); // TODO: Make a property for that
    156. }
    157.  
    158.  
    159. //setCursor(Qt::OpenHandCursor); //TODO? Make a property for the cursor
    160.  
    161. Qt::DropAction action = drag->exec(m_supportedActions, m_defaultAction);
    162. emit drop(action);
    163. }
    To copy to clipboard, switch view to plain text mode 


    Qt Code:
    1. #include "DeclarativeDropArea.h"
    2. #include "DeclarativeDragDropEvent.h"
    3.  
    4. #include <QGraphicsSceneDragDropEvent>
    5. #include <QMimeData>
    6.  
    7. DeclarativeDropArea::DeclarativeDropArea(QDeclarativeItem *parent)
    8. : QDeclarativeItem(parent),
    9. m_enabled(true)
    10. {
    11. setAcceptDrops(m_enabled);
    12. }
    13.  
    14. void DeclarativeDropArea::dragEnterEvent(QGraphicsSceneDragDropEvent *event) {
    15. DeclarativeDragDropEvent dde(event, this);
    16. emit dragEnter(&dde);
    17. }
    18.  
    19. void DeclarativeDropArea::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
    20. {
    21. DeclarativeDragDropEvent dde(event, this);
    22. emit dragLeave(&dde);
    23. }
    24.  
    25. void DeclarativeDropArea::dropEvent(QGraphicsSceneDragDropEvent *event)
    26. {
    27. DeclarativeDragDropEvent dde(event, this);
    28. emit drop(&dde);
    29. }
    30.  
    31. bool DeclarativeDropArea::isEnabled() const
    32. {
    33. return m_enabled;
    34. }
    35.  
    36. void DeclarativeDropArea::setEnabled(bool enabled)
    37. {
    38. if (enabled == m_enabled) {
    39. return;
    40. }
    41.  
    42. m_enabled = enabled;
    43. setAcceptDrops(m_enabled);
    44. emit enabledChanged();
    45. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Inheriting QwtPlot and Q_OBJECT
    By gpsgek in forum Qwt
    Replies: 2
    Last Post: 5th July 2011, 06:09
  2. Replies: 1
    Last Post: 23rd February 2010, 15:57
  3. A Object inheriting from QGraphicsLineItem
    By jano_alex_es in forum Newbie
    Replies: 15
    Last Post: 15th July 2009, 09:25
  4. Inheriting from QwtPlotCurve problems
    By dbrmik in forum Qwt
    Replies: 5
    Last Post: 1st April 2009, 14:02
  5. Inheriting QListViewItem
    By ct in forum Newbie
    Replies: 1
    Last Post: 17th March 2006, 05:52

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.