Results 1 to 5 of 5

Thread: negative number

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2025
    Posts
    25
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default negative number

    Hi everyone, I can't read a negative number in DoubleSpinBox.

    I have a minimum of -1 and a maximum of -5.

    line : 197/198

    What should I do? Regards.

    Qt Code:
    1. #include "modifcons.h"
    2.  
    3. ModifCons::ModifCons()
    4. {
    5. qDebug() << "modifcons";
    6.  
    7. m_modifConsignes = new Consignes(QString("settings/consignes.ini"), QSettings::IniFormat);
    8.  
    9. m_window2 = new QWidget;
    10. m_window2 ->setFixedSize(1000,600);
    11. m_window2 ->setWindowTitle("Modification Consignes Gainable");
    12. adjustSize();
    13.  
    14. m_label2 = new QLabel(m_window2);
    15. m_label2 ->setPixmap(QPixmap("/home/ludo/Qt/test2/build/images/modifCons.jpg"));
    16. m_label2 ->showMaximized();
    17.  
    18. select = new QComboBox(m_window2);
    19. select ->setGeometry(50,50,900,120);
    20. for (int i(0); i < 16; ++i)
    21. {
    22. select ->addItem(QString::number(i));
    23. }
    24. select ->setStyleSheet("font-size: 30px;");
    25. select ->setItemText(0,"Consigne Ete/Hiver :");
    26. select ->setItemText(1,"Consigne Canicule :");
    27. select ->setItemText(2,"Consigne Bloquage Chauffage :");
    28. select ->setItemText(3,"Consigne Mode Degivrage (Naturel ou Electrique) Chauffage :");
    29. select ->setItemText(4,"Consigne Grande Vitesse Ventilation Exterieur Chauffage :");
    30. select ->setItemText(5,"Consigne Grande Vitesse Ventilation Exterieur Froid :");
    31. select ->setItemText(6,"Consigne Fin Degivrage Chauffage :");
    32. select ->setItemText(7,"Consigne Depart Chauffage en Mode Chauffage :");
    33. select ->setItemText(8,"Consigne Depart Froid en Mode Chauffage :");
    34. select ->setItemText(9,"Consigne Petite Vitesse Ventilation Interieur Chauffage :");
    35. select ->setItemText(10,"Consigne Depart Froid en Mode Froid :");
    36. select ->setItemText(11,"Consigne Depart Chauffage en Mode Froid :");
    37. select ->setItemText(12,"Consigne Petite Vitesse Ventilation Interieur Froid :");
    38. select ->setItemText(13,"Consigne Depart Ventilation Interieur Chauffage :");
    39. select ->setItemText(14,"Consigne Lancement Degivrage Froid :");
    40. select ->setItemText(15,"Consigne Fin Degivrage Froid :");
    41.  
    42. m_valid1 = new QPushButton("valid",m_window2);
    43. m_valid1 ->setGeometry(50,180,240,120);
    44. m_valid1 ->setStyleSheet("font-size: 30px;");
    45.  
    46. m_quit1 = new QPushButton("quitter",m_window2);
    47. m_quit1 ->setGeometry(710,440,240,120);
    48. m_quit1 ->setStyleSheet("font-size: 30px;background-color: red");
    49.  
    50. connect(m_valid1, &QPushButton::clicked, this, &ModifCons::selectCons);
    51. connect(m_quit1,&QPushButton::clicked,m_quit1,[this](){m_window2 ->close(); delete m_window2;});
    52.  
    53. m_window2 ->show();
    54. }
    55.  
    56. void ModifCons::adjustCons()
    57. {
    58. m_selCons = new QDoubleSpinBox (m_window2);
    59. m_selCons ->setStyleSheet("QDoubleSpinBox::down-button{width: 150} QDoubleSpinBox::up-button{width: 150}");
    60. m_selCons ->setFont(QFont("Times", 20, QFont::Bold));
    61. m_selCons ->setValue(consSelect);
    62. m_selCons ->setRange(consMini,consMaxi);
    63. m_selCons ->setSingleStep(0.1);
    64. m_selCons ->setPrefix("Valeur: ");
    65. m_selCons ->setSuffix(" °C");
    66. m_selCons ->setGeometry(50,310,400,120);
    67. m_selCons ->show();
    68.  
    69. m_valid2 = new QPushButton("ok",m_window2);
    70. m_valid2 ->setGeometry(50,440,240,120);
    71. m_valid2 ->setStyleSheet("font-size: 30px;");
    72. m_valid2 ->show();
    73.  
    74. connect(m_valid2,&QPushButton::clicked,m_valid2,[this](){saveCons(); m_selCons ->close();});
    75. }
    76.  
    77. void ModifCons::selectCons()
    78. {
    79. m_modifConsignes ->lireConsignesGainable();
    80.  
    81. switch (select ->currentIndex())
    82. {
    83. case 0:
    84. consSelect = m_modifConsignes ->consigneEteHiver; // 13.5
    85. consMini = 10.0;
    86. consMaxi = 16.0;
    87. adjustCons();
    88. m_valid1 ->hide();
    89. break;
    90.  
    91. case 1:
    92. consSelect = m_modifConsignes ->consigneCanicule; // 30.0
    93. consMini = 28.0;
    94. consMaxi = 32.0;
    95. adjustCons();
    96. m_valid1 ->hide();
    97. break;
    98.  
    99. case 2:
    100. consSelect = m_modifConsignes ->consigneBlocChauf; // 11.0
    101. consMini = 9.0;
    102. consMaxi = 13.0;
    103. adjustCons();
    104. m_valid1 ->hide();
    105. break;
    106.  
    107. case 3:
    108. consSelect = m_modifConsignes ->consigneModeDegCh; // 5.0
    109. consMini = 3.0;
    110. consMaxi = 7.0;
    111. adjustCons();
    112. m_valid1 ->hide();
    113. break;
    114.  
    115. case 4:
    116. consSelect = m_modifConsignes ->consigneGrVitExtCh; // 5.0
    117. consMini = 3.0;
    118. consMaxi = 7.0;
    119. adjustCons();
    120. m_valid1 ->hide();
    121. break;
    122.  
    123. case 5:
    124. consSelect = m_modifConsignes ->consigneGrVitExtFr; // 20.0
    125. consMini = 16.0;
    126. consMaxi = 22.0;
    127. adjustCons();
    128. m_valid1 ->hide();
    129. break;
    130.  
    131. case 6:
    132. consSelect = m_modifConsignes ->consigneFinDegCh; // 12.5
    133. consMini = 10.5;
    134. consMaxi = 14.5;
    135. adjustCons();
    136. m_valid1 ->hide();
    137. break;
    138.  
    139. case 7:
    140. consSelect = m_modifConsignes ->consigneDepartChauffageEnChauffage; //
    141. consMini = 17.0;
    142. consMaxi = 21.0;
    143. adjustCons();
    144. m_valid1 ->hide();
    145. break;
    146.  
    147. case 8:
    148. consSelect = m_modifConsignes ->consigneDepartFroidEnChauffage; //
    149. consMini = 22.0;
    150. consMaxi = 25.0;
    151. adjustCons();
    152. m_valid1 ->hide();
    153. break;
    154.  
    155. case 9:
    156. consSelect = m_modifConsignes ->consignePeVitIntCh; // 23.5
    157. consMini = 21.5;
    158. consMaxi = 25.5;
    159. adjustCons();
    160. m_valid1 ->hide();
    161. break;
    162.  
    163. case 10:
    164. consSelect = m_modifConsignes ->consigneDepartFroidEnFroid; //
    165. consMini = 21.0;
    166. consMaxi = 25.0;
    167. adjustCons();
    168. m_valid1 ->hide();
    169. break;
    170.  
    171. case 11:
    172. consSelect = m_modifConsignes ->consigneDepartChauffageEnFroid; //
    173. consMini = 17.0;
    174. consMaxi = 21.0;
    175. adjustCons();
    176. m_valid1 ->hide();
    177. break;
    178.  
    179. case 12:
    180. consSelect = m_modifConsignes ->consignePeVitIntFr; // 23.0
    181. consMini = 21.0;
    182. consMaxi = 25.0;
    183. adjustCons();
    184. m_valid1 ->hide();
    185. break;
    186.  
    187. case 13:
    188. consSelect = m_modifConsignes ->consigneDepartVentIntCh; // 35.0
    189. consMini = 30.0;
    190. consMaxi = 40.0;
    191. adjustCons();
    192. m_valid1 ->hide();
    193. break;
    194.  
    195. case 14:
    196. consSelect = m_modifConsignes ->consigneDegFr; // -3.0
    197. consMini = -5;
    198. consMaxi = -1;
    199. adjustCons();
    200. m_valid1 ->hide();
    201. break;
    202.  
    203. case 15:
    204. consSelect = m_modifConsignes ->consigneFinDegFr; // 15.0
    205. consMini = 13.0;
    206. consMaxi = 17.0;
    207. adjustCons();
    208. m_valid1 ->hide();
    209. break;
    210.  
    211. default:
    212. break;
    213. }
    214. }
    215. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,315
    Thanks
    314
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: negative number

    Every time you call adjustCons() you are creating a new spin box and a new push button, and you are overwriting the pointers of any existing member variables named m_selCons and m_valid2. The old widgets assigned to those variables exist and are active, even though you have hidden them on screen by putting the new widgets in exactly the same places. So I don't know which spin box you are changing - an old one or a new one?

    I do not see anything in your code where you actually read the spin box value.

    Calling m_selCons->close() in the push button slot does not delete the widget, it just hides it.

    Why are you not using layouts to manage your widgets? Using setGeometry() is not correct; if you use layouts, then your widget layout will adjust automatically when the window is resized.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 1
    Last Post: 5th March 2012, 06:34
  2. How to zoom in negative X and Y axis ?
    By biplab777 in forum Qwt
    Replies: 0
    Last Post: 9th June 2009, 10:55
  3. color image to negative
    By sm in forum Newbie
    Replies: 1
    Last Post: 29th January 2008, 15:25
  4. negative images
    By tommy in forum Qt Programming
    Replies: 3
    Last Post: 22nd January 2008, 10:41
  5. Are "negative filters" possible??
    By ht1 in forum Qt Programming
    Replies: 1
    Last Post: 30th November 2007, 21:23

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.