Results 1 to 6 of 6

Thread: reading integers from QTextEdit doesn't go right ?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2013
    Posts
    3
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default reading integers from QTextEdit doesn't go right ?

    I have 6 push buttons, each one draws a different shape, and I have multiple textEdits that takes coordinates from user as an input, the problem is wheneve I enter the coordinates of a line and save it in a variable and call the method draw it doesnt draw anything, though I've tried the draw functions with numbers as parameters and worked just fine, what could be the problem ? I am still a newbie to QT

    Qt Code:
    1. #include "dialog.h"
    2. #include "ui_dialog.h"
    3. #include<QPixmap>
    4. #include <QLayout>
    5. #include <QLabel>
    6. bool p1=false;
    7. bool p2=false;
    8. bool p3=false;
    9. bool p4=false;
    10. bool p5=false;
    11. bool p6=false;
    12. bool ok=true;
    13. int initX,initY,x2,y2,x3,y3,r1,r2,l,w;
    14. QPixmap *pm;
    15. Dialog::Dialog(QWidget *parent) :
    16. QDialog(parent),
    17. ui(new Ui::Dialog)
    18. {
    19. ui->setupUi(this);
    20. }
    21.  
    22. Dialog::~Dialog()
    23. {
    24. delete ui;
    25. }
    26. void Dialog::paintEvent(QPaintEvent *e){
    27. QDialog::paintEvent(e);
    28. //QLabel::paintEvent(event);
    29. QPainter painter(this);
    30. if(p1){
    31.  
    32. painter.drawEllipse(initX,initY,r1,r1);
    33. painter.save();
    34. p1=false;
    35. }
    36. if(p2){
    37. painter.drawEllipse(initX,initY,r1,r2);
    38. painter.save();
    39. p1=false;
    40. }
    41. if(p3){
    42. painter.drawLine(initX,initY,x2,y2);
    43. painter.save();
    44. p3=false;
    45. }
    46. if(p4){
    47. painter.drawRect(initX,initY,l,l);
    48. painter.save();
    49. p4=false;
    50. }
    51.  
    52. if(p5){
    53. painter.drawRect(initX,initY,l,w);
    54. painter.save();
    55. p5=false;
    56. }
    57. if(p6){
    58. painter.drawLine(initX,initY,x2,y3);
    59. painter.save();
    60. painter.drawLine(x2,y2,x3,y3);
    61. painter.save();
    62. painter.drawLine(x3,y3,initX,initY);
    63. painter.save();
    64. p6=false;
    65. }
    66. }
    67. void Dialog::on_pushButton_3_clicked()
    68. {
    69. p3=true;
    70. update();
    71. }
    72.  
    73.  
    74.  
    75. void Dialog::on_pushButton_clicked()
    76. {
    77. p1=true;
    78. update();
    79. }
    80.  
    81. void Dialog::on_pushButton_2_clicked()
    82. {
    83. p2=true;
    84. update();
    85. }
    86.  
    87. void Dialog::on_pushButton_4_clicked()
    88. {
    89. p4=true;
    90. update();
    91. }
    92.  
    93. void Dialog::on_pushButton_5_clicked()
    94. {
    95. p5=true;
    96. update();
    97. }
    98.  
    99. void Dialog::on_pushButton_6_clicked()
    100. {
    101. p6=true;
    102. update();
    103. }
    104.  
    105. void Dialog::on_textEdit_textChanged()
    106. {
    107. // ui->textEdit->
    108. initX=ui->textEdit->toPlainText().toInt(&ok,10);
    109. // initX=10;
    110. }
    111.  
    112. void Dialog::on_textEdit_2_textChanged()
    113. {
    114. initY=ui->textEdit->toPlainText().toInt(&ok,10);
    115. //initY=10;
    116. }
    117.  
    118. void Dialog::on_textEdit_3_textChanged()
    119. {
    120. x2=ui->textEdit->toPlainText().toInt(&ok,10);
    121. // x2=100;
    122. }
    123.  
    124. void Dialog::on_textEdit_4_textChanged()
    125. {
    126. y2=ui->textEdit->toPlainText().toInt(&ok,10);
    127. // y2=100;
    128. }
    129.  
    130. void Dialog::on_textEdit_5_textChanged()
    131. {
    132. x3=ui->textEdit->toPlainText().toInt(&ok,10);
    133. }
    134.  
    135. void Dialog::on_textEdit_6_textChanged()
    136. {
    137. y3=ui->textEdit->toPlainText().toInt(&ok,10);
    138. }
    139.  
    140. void Dialog::on_textEdit_7_textChanged()
    141. {
    142. r1=ui->textEdit->toPlainText().toInt(&ok,10);
    143. }
    144.  
    145. void Dialog::on_textEdit_8_textChanged()
    146. {
    147. r2=ui->textEdit->toPlainText().toInt(&ok,10);
    148. }
    149.  
    150. void Dialog::on_textEdit_9_textChanged()
    151. {
    152. l=ui->textEdit->toPlainText().toInt(&ok,10);
    153. }
    154.  
    155. void Dialog::on_textEdit_10_textChanged()
    156. {
    157. w=ui->textEdit->toPlainText().toInt(&ok,10);
    158. }
    To copy to clipboard, switch view to plain text mode 

  2. The following user says thank you to mernarezk for this useful post:

    louboutinoutlet (1st December 2013)

Similar Threads

  1. add two integers
    By Gishan in forum Newbie
    Replies: 3
    Last Post: 8th September 2012, 08:44
  2. QTextEdit doesn't append text
    By Luc4 in forum Qt Programming
    Replies: 7
    Last Post: 13th June 2010, 22:45
  3. Only integers from QFontMetricsF width
    By StevenB in forum Qt Programming
    Replies: 3
    Last Post: 16th May 2008, 21:59
  4. how to get integers from mysql
    By eleanor in forum Qt Programming
    Replies: 9
    Last Post: 8th November 2007, 16:25
  5. reading QTextEdit from file
    By incapacitant in forum Newbie
    Replies: 3
    Last Post: 29th March 2006, 21:45

Tags for this Thread

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.