i have a class named display that creates a scene that is later added to a graphicsview
the display class has two slots, i want to move, hide , set text to items using the slots. the .h and .cpp for the display class is

as you can see i tried some move functions in the slots but the items do not move. what am i doing wrong?

Qt Code:
  1. #ifndef DISPLAY_H #define DISPLAY_H
  2. #include <QGraphicsView>
  3. #include <QPushButton>
  4. #include <QGraphicsRectItem>
  5. #include <QGraphicsBlurEffect>
  6. class display
  7. : public QObject
  8. {
  9. Q_OBJECT
  10. public:
  11. display();
  12. QPushButton *buttonExit;
  13. QPushButton *buttonCalibrate;
  14. QGraphicsRectItem *messagerect;
  15. QString orientation;
  16. QString anglestring;
  17. QGraphicsRectItem *anglerect1;
  18. public slots:
  19. void setOrientation(QString neworientation);
  20. void setAngles(double newanglexy,double newanglexz,double newangleyz);
  21. private:
  22. double anglexy ;
  23. double anglexz ;
  24. double angleyz ;
  25. };
  26. #endif // DISPLAY_H
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. #include "display.h" #include <QtGui/QApplication>
  2. #include <QDebug>
  3. #include <QDesktopWidget>
  4. display::display()
  5. {
  6. anglexy = 0;
  7. anglexz = 0;
  8. angleyz = 0;
  9. anglestring = "0";
  10. const int screenwidth = QApplication::desktop()->width();
  11. const int screenheight = QApplication::desktop()->height();
  12. const int buttonheight = 60;
  13. const int tubebackwidth = 300;
  14. const int tubebackheight = 100;
  15. qDebug() << "width: "+ QString::number(screenwidth) +" height: "+ QString::number(screenheight);
  16. scene = new QGraphicsScene();
  17. scene->setSceneRect(0,0,screenwidth,screenheight);
  18. scene->setBackgroundBrush(Qt::black);
  19. QGraphicsRectItem *tubeback = new QGraphicsRectItem(0, scene );
  20. tubeback->setRect( screenwidth/2-tubebackwidth/2,screenheight/2-tubebackheight/2-buttonheight/2, tubebackwidth, tubebackheight );
  21. //tubeback1->setFlag( QGraphicsItem::ItemIsMovable );
  22. tubeback->setBrush(Qt::yellow);
  23. tubeback->setGraphicsEffect(new QGraphicsBlurEffect());
  24. QPen pen1;
  25. pen1.setColor(Qt::black);
  26. pen1.setWidth(10);
  27. pen1.setStyle(Qt::DotLine);
  28. QGraphicsEllipseItem *tubefront = new QGraphicsEllipseItem(0, scene );
  29. tubefront->setRect( screenwidth/2-40,screenheight/2-tubebackheight/2-buttonheight/2+5, 80, tubebackheight-50 );
  30. tubefront->setFlag( QGraphicsItem::ItemIsMovable );
  31. tubefront->setBrush(Qt::white);
  32. tubefront->setGraphicsEffect(new QGraphicsOpacityEffect());
  33. tubefront->setGraphicsEffect(new QGraphicsBlurEffect());
  34. QGraphicsLineItem *line1 = new QGraphicsLineItem(0,scene);
  35. line1->setLine(screenwidth/2-tubebackwidth/6,screenheight/2-tubebackheight/2-buttonheight/2, screenwidth/2-tubebackwidth/6,screenheight/2-tubebackheight/2-buttonheight/2+tubebackheight);
  36. line1->setPen(pen1);
  37. QGraphicsLineItem *line2 = new QGraphicsLineItem(0,scene);
  38. line2->setLine(screenwidth/2+tubebackwidth/6,screenheight/2-tubebackheight/2-buttonheight/2, screenwidth/2+tubebackwidth/6,screenheight/2-tubebackheight/2-buttonheight/2+tubebackheight);
  39. line2->setPen(pen1);
  40. //se intiaza un buton cu un apel calificat catre functia tr() pentru a traduce textul butonului
  41. //: This name refers to the Calibrate Button's name
  42. QPushButton *buttonCalibrate = new QPushButton(QObject::tr("Calibrate"));
  43. #ifdef Q_WS_MAEMO
  44. buttonCalibrate->setMaximumSize(screenwidth/2,buttonheight);
  45. //#elif defined(Q_WS_MAEMO_5)
  46. #else Q_OS_SYMBIAN
  47. buttonCalibrate->setMaximumSize(screenwidth/2,buttonheight);
  48. #endif
  49. //: This name refers to the Exit Button's name
  50. QPushButton *buttonExit = new QPushButton(QObject::tr("Exit"));
  51. #ifdef Q_WS_MAEMO
  52. buttonExit->setMaximumSize(screenwidth/2,buttonheight);
  53. #else Q_OS_SYMBIAN
  54. buttonExit->setMaximumSize(screenwidth/2,buttonheight);
  55. #endif
  56. scene->addWidget(buttonCalibrate);
  57. scene->addWidget(buttonExit);
  58. buttonCalibrate->move(0,screenheight-buttonheight);
  59. buttonExit->move(screenwidth/2,screenheight-buttonheight);
  60. QGraphicsRectItem *messagerect= new QGraphicsRectItem(0, scene );
  61. messagerect->setRect( 0,0, 280, 80 );
  62. messagerect->setFlag( QGraphicsItem::ItemIsMovable );
  63. messagerect->setBrush(Qt::black);
  64. QGraphicsSimpleTextItem *messageitem = new QGraphicsSimpleTextItem (messagerect );
  65. messageitem->setText(QObject::tr(" Keep the phone steady and level\n about to calibrate the phone \n for this orientation..."));
  66. messageitem->setBrush(Qt::white);
  67. messagerect->moveBy(screenwidth/2-140,screenheight/2-buttonheight/2-40);
  68. messagerect->hide();
  69. anglerect1= new QGraphicsRectItem(0 , scene );
  70. anglerect1->setRect( 0,0, 30, 30 );
  71. anglerect1->setFlag( QGraphicsItem::ItemIsMovable );
  72. anglerect1->setBrush(Qt::black);
  73. angleitem1 = new QGraphicsSimpleTextItem (anglerect1 );
  74. angleitem1->setText("anglestring""");
  75. angleitem1->setBrush(Qt::white);
  76. anglerect1->moveBy(screenwidth/2-5,screenheight/2-buttonheight/2-100);
  77. //anglerect1->hide();
  78. //The connect() method connects a signal to the slot. When we click on the quit button, the clicked() signal is generated. The qApp is a global pointer to the application object. It is defined in the <QApplication> header file. The quit() method is called, when the clicked signal is emitted.
  79. QObject::connect(buttonExit, SIGNAL(clicked()), qApp, SLOT(quit()));
  80. }
  81. void display::setOrientation(QString neworientation)
  82. {
  83. if (neworientation != orientation) {
  84. orientation = neworientation;
  85. qDebug() << "display orientation: " << orientation;
  86. // buttonCalibrate->move(0,0);
  87.  
  88. }
  89. }
  90. void display::setAngles(double newanglexy,double newanglexz,double newangleyz)
  91. {
  92. if (newanglexy != anglexy) {
  93. anglexy = newanglexy;
  94. anglestring.sprintf("%.0f", anglexy);
  95.  
  96. anglerect1->hide();
  97. angleitem1->setText(anglestring);
  98. qDebug() << "anglerecived "<<anglestring;
  99. return anglerect1->hide();
  100. return scene->update();
  101. }
  102. }
To copy to clipboard, switch view to plain text mode