Results 1 to 20 of 66

Thread: linking of combox with lineEdit.

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    8
    Thanked 133 Times in 128 Posts

    Default Re: linking of combox with lineEdit.

    you have to pass the parent to lineedit

    new QLineEdit(this);

  2. #2
    Join Date
    Jul 2009
    Posts
    55
    Thanks
    3

    Default Re: linking of combox with lineEdit.

    Quote Originally Posted by MrDeath View Post
    you have to pass the parent to lineedit

    new QLineEdit(this);
    eh.. i got this error..

    QLineEdit::QLineEdit(QWidget *)' : cannot convert parameter 1 from 'Node *const ' to 'QWidget *'

    all the node is drawn using painter. i cant do this.

    nameLine = new QLineEdit(painter);

    argh.

  3. #3
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    8
    Thanked 133 Times in 128 Posts

    Default Re: linking of combox with lineEdit.

    you have to make the lineEdit the child of the widget you want to show it on..
    so pass the parent as the pointer of that widget..
    and you havent fully read the tutorial yet.

  4. #4
    Join Date
    Jul 2009
    Posts
    55
    Thanks
    3

    Default Re: linking of combox with lineEdit.

    i really dont know how man. below is the void i wanan add the lineedit into.

    the lineedit command is at the end of this void.


    Qt Code:
    1. void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
    2. {
    3. QPixmap pixmap2(200,100);
    4. pixmap2.fill(Qt::white);
    5. QPixmap pix;
    6. QPainter painter1(&pixmap);
    7. QPainter painter2(&pixmap2);
    8. QString id;
    9. Q_UNUSED(option);
    10.  
    11. QSettings settings;
    12. nodeAlertTemp = settings.value("NodeAlertTemp", 10).toDouble();
    13.  
    14. if (nodeData.addr!=0){
    15. if(nodeData.fadeNumber>5&&nodeData.deletedNode!=0)
    16. {
    17. nodeData.fadeNumber-=fade_speed;
    18. if (nodeData.fadeNumber<=5){
    19.  
    20. nodeData.fadeNumber=0;
    21. nodeData.deletedNode=1;
    22. index_number=0;
    23. }
    24. }
    25.  
    26. if(nodeData.fadeNumber<255&&nodeData.newNode!=0)
    27. {
    28. nodeData.fadeNumber+=fade_speed;
    29. if (nodeData.fadeNumber>=255)
    30. {
    31. nodeData.fadeNumber=255;
    32. nodeData.newNode=0;
    33. //current_updateData(index_number);
    34. index_number=0;
    35. }
    36. }
    37. }
    38. // Draw the grey shadow for a 3d effect.
    39. painter->setPen(Qt::NoPen);
    40. painter->setBrush (QColor(0x80, 0x80, 0x80,(nodeData.fadeNumber)));
    41. painter->drawEllipse(-45, -45, 100, 100);
    42.  
    43. // Set gradient and color of the node
    44. QRadialGradient gradient(0, 0, 50, -20, -20);// access points
    45.  
    46. if (nodeData.addr==0&&updated == true)
    47. {
    48. // Mouse click on node or an update of node data~
    49. gradient.setCenter(3, 3);
    50. gradient.setFocalPoint(3, 3);
    51. gradient.setColorAt(1, nodeColor.light(120));
    52. gradient.setColorAt(.5, nodeColorDark.light(120));
    53. gradient.setColorAt(0, nodeColorDark.light(120));
    54. updated = false;
    55. painter->setBrush(gradient);
    56. }
    57. else if (nodeData.addr==0&&updated == false)
    58. {
    59. gradient.setColorAt(0, nodeColor.light(150));
    60. gradient.setColorAt(1, nodeColorDark);
    61. painter->setBrush(gradient);
    62. }
    63. // end devices
    64. if (nodeData.addr!=0&&updated == true)
    65. {
    66. // Mouse click on node or an update of node data~
    67. gradient.setCenter(3, 3);
    68. gradient.setFocalPoint(3, 3);
    69. gradient.setColorAt(1, nodeColor);
    70. gradient.setColorAt(.5, nodeColor);
    71. gradient.setColorAt(0, nodeColor);
    72. updated = false;
    73. painter->setBrush(gradient);
    74. }
    75. else if (nodeData.addr!=0&&updated == false)
    76. {
    77. gradient.setColorAt(0, nodeColor);
    78. gradient.setColorAt(.95, nodeColorDark);
    79. gradient.setColorAt(1, nodeColor);
    80. painter->setBrush(gradient);
    81. }
    82.  
    83.  
    84. // painter->setBrush(gradient);
    85. // Draw black circle around the node
    86. painter->setPen(QColor(0, 0, 0,(nodeData.fadeNumber)));
    87. // Draw the node
    88. painter->drawEllipse(-50, -50, 100, 100);
    89.  
    90. //x new text
    91. // White pen for text
    92. if (nodeData.addr==0)
    93. {
    94. painter->setPen(QPen(Qt::white, 1));
    95. }
    96. else
    97. {
    98. if(nodeData.re<100)
    99. {
    100. painter->setPen(QColor(0, 0, 0,(nodeData.fadeNumber)));
    101. }
    102. else
    103. {
    104. painter->setPen(QColor(0xff, 0xff, 0xff,(nodeData.fadeNumber)));
    105. }
    106. }
    107. QString qsTemp;
    108. QString qsTemp2;
    109. // Write RE
    110. if (nodeData.re>100)
    111. {
    112. rebyte=nodeData.re-100;
    113. }
    114. else
    115. {
    116. rebyte=nodeData.re;
    117. }
    118.  
    119. if (rebyte>4&&nodeData.addr>0)
    120. {
    121. qsTemp.sprintf("%d Sec", rebyte);//rebyte
    122. painter->setFont(timeFont);
    123. painter->drawText(-50,+8,100,20,Qt::AlignCenter , qsTemp,0);
    124. }
    125. else if (nodeData.addr>0)
    126. {
    127. qsTemp.sprintf("%d Min", rebyte);
    128. painter->setFont(timeFont);
    129. painter->drawText(-50,+8,100,20,Qt::AlignCenter , qsTemp,0);
    130. }
    131. else if (nodeData.addr==0)
    132. {
    133. //qsTemp = timeStamp.toString("hh:mm:ss");
    134. qsTemp = timeStamp.toString(Qt::LocalDate);
    135.  
    136. //qsTemp.sprintf("TxCt: %d", cnt_rf);// for Jeff battery test only
    137. painter->setFont(timeFont);
    138. painter->drawText(-50,+5,100,20,Qt::AlignCenter , qsTemp,0);
    139. }
    140. // Write the battery voltage
    141. qsTemp.sprintf("%.1fV", nodeData.voltage);
    142. painter->setFont(battFont);
    143. painter->drawText(-50,+25,100,20,Qt::AlignCenter , qsTemp,0);
    144.  
    145. // Set text in the node
    146. // Write the temperature
    147. if(celsius)
    148. {
    149. qsTemp.sprintf("%.1f°C", ((nodeData.temp-32.0)/1.8));
    150. }
    151. else
    152. {
    153. qsTemp.sprintf("%.1f°F", nodeData.temp);
    154. }
    155. if (nodeData.addr==0) //node 0
    156. {
    157. //xpainter->setFont(tempFont);
    158. painter->setFont(addrFont);
    159. painter->drawText(-50,-45,100,40,Qt::AlignCenter , qsTemp,0);
    160. }
    161. else
    162. {
    163. painter->setFont(timeFont);
    164. painter->drawText(-50,-48,100,40,Qt::AlignCenter , qsTemp,0);
    165. }
    166. if (nodeData.addr==0) //node 0
    167. {
    168. // Write node number
    169. //qsTemp.sprintf("Node: %d", nodeData.addr);
    170. qsTemp.sprintf("Access Point");
    171. //xpainter->setFont(addrFont);
    172. painter->setFont(timeFont);
    173. painter->drawText(-50,-15,100,20,Qt::AlignCenter , qsTemp,0);
    174. }
    175. else
    176. {
    177. // Write node number
    178. // end device details
    179.  
    180. qsTemp.sprintf("End Device %d", nodeData.addr);
    181. //xpainter->setFont(addrFont);
    182. painter->setFont(timeFont);
    183. painter->drawText(-50,-22,100,20,Qt::AlignCenter , qsTemp,0);
    184.  
    185. //Write signal strength in ED node
    186. if (nodeData.strength > 21)
    187. {
    188. qsTemp.sprintf("Strong", nodeData.strength);
    189. painter->setFont(strengthFont);
    190. painter->drawText(-50,-8,100,20,Qt::AlignCenter , qsTemp,0);
    191. }
    192. else if (nodeData.strength > 15)
    193. {
    194. qsTemp.sprintf("Medium", nodeData.strength);
    195. painter->setFont(strengthFont);
    196. painter->drawText(-50,-8,100,20,Qt::AlignCenter , qsTemp,0);
    197. }
    198. else
    199. {
    200. qsTemp.sprintf("Weak", nodeData.strength);
    201. painter->setFont(strengthFont);
    202. painter->drawText(-50,-8,100,20,Qt::AlignCenter , qsTemp,0);
    203. }
    204. //temperture alert,
    205. if(nodeData.temp > (nodeAlertTemp*9)/5+32.0)
    206. {
    207. painter->setPen(Qt::NoPen);
    208. painter->setBrush (QColor(0x80, 0x80, 0x80,(nodeData.fadeNumber)));
    209. painter->drawEllipse(-45, -45, 100, 100);
    210. gradient.setCenter(3, 3);
    211. gradient.setFocalPoint(3, 3);
    212. QRadialGradient gradient(0, 0, 50, -20, -20);
    213. gradient.setColorAt(1, nodeAlertColor);
    214. gradient.setColorAt(.5, nodeAlertColorDark);
    215. gradient.setColorAt(0, nodeAlertColorDark);
    216. painter->setBrush(gradient);
    217. painter->setPen(QColor(0, 0, 0,(nodeData.fadeNumber)));
    218. painter->drawEllipse(-50, -50, 100, 100);
    219. if(celsius)
    220. {
    221. qsTemp.sprintf("ALERT!\n\ End Device %d\n\ %.1f°C\n\ ", nodeData.addr, ((nodeData.temp-32.0)/1.8));
    222. painter->setPen(QPen(Qt::black, 0));
    223. painter->setFont(timeFont);
    224. painter->drawText(-50,-50,100,100,Qt::AlignCenter , qsTemp,0);
    225. }
    226. else
    227. {
    228. qsTemp.sprintf("ALERT!\n\ End Device %d\n\ %.1f°F\n\ ", nodeData.addr, nodeData.temp);
    229. painter->setPen(QPen(Qt::black, 0));
    230. painter->setFont(timeFont);
    231. painter->drawText(-50,-50,100,100,Qt::AlignCenter , qsTemp,0);
    232. }
    233. }
    234. painter->drawRect(-43,-20,85,15);
    235. [COLOR="blue"]nameLine = new QLineEdit();
    236. nameLine->setGeometry(QRect(-43,-20,85,15));[/COLOR] }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    8
    Thanked 133 Times in 128 Posts

    Default Re: linking of combox with lineEdit.

    so your are creating a lineEdit inside the paint method which would be called thousands of time per second... so every time you will be creating the lineEdit and creating a memory leak. The line edit should be created once in the main widget on which the painter is painting and use the pointer to the line edit in paint()

  6. #6
    Join Date
    Jul 2009
    Posts
    55
    Thanks
    3

    Default Re: linking of combox with lineEdit.

    OMG!! argh..

    i guess the main widget on which the painter pain on is here. so i write the command of the line edit here?

    Qt Code:
    1. QRectF Node::boundingRect() const
    2. {
    3. qreal adjust = 2;
    4. return QRectF(-50 - adjust, -50 - adjust,
    5. 110 + adjust, 110 + adjust);
    6. }
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Jul 2009
    Posts
    55
    Thanks
    3

    Default Re: linking of combox with lineEdit.

    hello~ Mr.Death~~~

  8. #8
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    8
    Thanked 133 Times in 128 Posts

    Default Re: linking of combox with lineEdit.

    hello there...

    make the line edit in constructor of you widget being painted.

  9. #9
    Join Date
    Jul 2009
    Posts
    55
    Thanks
    3

    Default Re: linking of combox with lineEdit.

    Quote Originally Posted by MrDeath View Post
    hello there...

    make the line edit in constructor of you widget being painted.
    sorry, but i dun get what you mean by in construtor of my widget

  10. #10
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    8
    Thanked 133 Times in 128 Posts

    Default Re: linking of combox with lineEdit.

    you have a widget subclass on which you use the QPainter rite?
    make lineedit a member of your qwidget subclass and new it in the constructor of that subclass.

    take a look at the example programs that comes with Qt please please....

  11. #11
    Join Date
    Jul 2009
    Posts
    55
    Thanks
    3

    Default Re: linking of combox with lineEdit.

    Quote Originally Posted by MrDeath View Post
    take a look at the example programs that comes with Qt please please....
    argh argh argh. why i dun seem to understand. lol. which example? do i look into?

  12. #12
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    8
    Thanked 133 Times in 128 Posts

    Default Re: linking of combox with lineEdit.

    widget painting example..

Similar Threads

  1. Qt linking problem
    By LovesTha in forum Newbie
    Replies: 3
    Last Post: 30th March 2009, 23:31
  2. How to update lineEdit
    By HelloDan in forum Qt Programming
    Replies: 9
    Last Post: 17th February 2009, 07:01
  3. Copy / Paste doesn't work with LineEdit
    By ia32 in forum Qt Tools
    Replies: 2
    Last Post: 5th May 2008, 21:44
  4. Replies: 4
    Last Post: 20th February 2006, 09:11
  5. subclassing or redrawing a lineEdit
    By jayw710 in forum Qt Programming
    Replies: 2
    Last Post: 7th February 2006, 18:26

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.