Results 1 to 8 of 8

Thread: One dialog for several lcdnumber values?

  1. #1
    Join Date
    Apr 2011
    Posts
    9
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: One dialog for several lcdnumber values?

    Hi to all

    This is my first post, so, pleas, be gently.

    I am writing a test code for an application where I willl read data for 4 to 16 water tanks and present the values of these in several lcd numbers in the main window.
    If the user click on one image (one for each of the lcd numbers because the lcd numbers don't have the onclick event), I need to show a new window (in this case I have one QDialog), with the present tank value and a graphic with the last readings.

    The problem i sthat I have to create one QDialog for each of the tanks because the slot() don't accept a value in it's call.

    Can somebody explain, if possible, how can I create just one QDialog and pass a variable value to it, wich is the index of the tank, so I can read the log file and plot the data?

    This is my present source code. I have mixed some C++ and C propositaly because I want to minimise the use of libs becaus ethis app will run in a Arm based board, with a 7 inch display (mini2440).:

    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "mainwindow.h"
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7. MainWindow w;
    8. w.showMaximized();
    9. return a.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 

    dialog1.cpp:
    Qt Code:
    1. #include "mainwindow.h"
    2. #include <dialog1.h>
    3.  
    4. Dialog::Dialog( QWidget* Parent, Qt::WFlags Flags ) : QDialog( Parent, Flags )
    5. {
    6. setWindowTitle( tr( "Tanque 1" ) );
    7. resize( QSize(800, 480).expandedTo(minimumSizeHint()) );
    8. setWindowFlags(this->windowFlags() & Qt::Window | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint);
    9. this->setStyleSheet( "background-image: url(:/images/background_main.png)");
    10.  
    11. QPushButton *Button = new QPushButton( tr( "ok" ), this );
    12. QLCDNumber *Tanque1Level = new QLCDNumber(5, this);
    13.  
    14. Tanque1Level->setGeometry( 10, 10, 180, 80 );
    15. Tanque1Level->setSmallDecimalPoint( false );
    16. Tanque1Level->setNumDigits( 5 );
    17. Tanque1Level->setSegmentStyle(QLCDNumber::Flat);
    18. Tanque1Level->setFrameShape(QLCDNumber::Box);
    19. Tanque1Level->setFrameShadow(QLCDNumber::Sunken);
    20. Tanque1Level->setMode(QLCDNumber::Dec);
    21. Tanque1Level->setStyleSheet("background: transparent;color:rgb(0,255,0); border: 2px solid grey;");
    22. Tanque1Level->display(12976);
    23.  
    24. Button->setGeometry( QRect( 750, 440, 40, 30 ) );
    25. connect( Button, SIGNAL( clicked() ), this, SLOT( close() ) );
    26.  
    27. }
    To copy to clipboard, switch view to plain text mode 

    dialog1.h:
    Qt Code:
    1. #include <QDialog>
    2. #include <QPushButton>
    3.  
    4. class Dialog : public QDialog
    5. {
    6. Q_OBJECT
    7.  
    8. public:
    9. Dialog( QWidget* parent = 0, Qt::WFlags Flags = 0 );
    10. ~Dialog() {};
    11.  
    12. private:
    13. QPushButton *Button;
    14.  
    15. };
    To copy to clipboard, switch view to plain text mode 

    mainwindow.h:
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4.  
    5. #define CR 13
    6. #define TIMEOUT_SERIAL 100
    7. #define TIMETOCHKSER 1000 // Check serial every TIMETOCHKSER ms
    8. #define TIMETOCREATELOG 3600000 // TIMETOCREATELOG ms, entre logs
    9. #define MAX_BUFF_LEN 1024
    10. #define BAUDRATE B9600
    11. #define FUELTANKCAP 15000
    12.  
    13.  
    14. #include "ui_mainwindow.h"
    15.  
    16. #include <QMainWindow>
    17. #include <QtGui/QApplication>
    18. #include <QPushButton>
    19. //#include <QProgressBar>
    20. #include <QDesktopWidget>
    21. #include <QTimer>
    22. #include <QString>
    23. #include <QMessageBox>
    24. #include <QLatin1String>
    25. #include <QLCDNumber>
    26. #include <QMainWindow>
    27. #include <QDockWidget>
    28.  
    29. #include <qdir.h>
    30.  
    31. #include <sys/io.h>
    32. #include <sys/time.h>
    33. #include <termios.h>
    34. #include <stdio.h>
    35. #include <unistd.h>
    36. #include <fcntl.h>
    37.  
    38.  
    39. namespace Ui {
    40. class MainWindow;
    41. }
    42.  
    43.  
    44. class MainWindow : public QMainWindow
    45. {
    46. Q_OBJECT
    47.  
    48. public:
    49. explicit MainWindow(QWidget *parent = 0);
    50. FILE *sfPtr;
    51. FILE *flog; // Log File descriptor
    52. bool CreateLogFile;
    53. int screenWidth, width;
    54. int screenHeight, height;
    55. int x, y, TankIndex;
    56. QSize windowSize;
    57. ~MainWindow();
    58.  
    59. private slots:
    60. void updateSerialData(void);
    61. void EnableLog(void);
    62. void View_tank1_Details(void);
    63. void View_tank2_Details(void);
    64. void View_tank3_Details(void);
    65. void View_tank4_Details(void);
    66. void View_tank5_Details(void);
    67. void View_tank6_Details(void);
    68. void View_tank7_Details(void);
    69. void View_tank8_Details(void);
    70. void View_tank9_Details(void);
    71. void View_tank10_Details(void);
    72. void View_tank11_Details(void);
    73. void View_tank12_Details(void);
    74. void View_tank13_Details(void);
    75. void View_tank14_Details(void);
    76. void View_tank15_Details(void);
    77. void View_tank16_Details(void);
    78. void View_tank_Details(int index);
    79. void dialog();
    80. private:
    81. Ui::MainWindow *ui;
    82. };
    83.  
    84. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    test1.pro:
    Qt Code:
    1. QT += core gui
    2.  
    3. TARGET = test1
    4. TEMPLATE = app
    5.  
    6. DEFINES = _TTY_POSIX_
    7.  
    8. SOURCES += main.cpp\
    9. mainwindow.cpp \
    10. dialog1.cpp
    11. HEADERS += mainwindow.h \
    12. dialog1.h
    13. FORMS += mainwindow.ui
    14.  
    15. RESOURCES += \
    16. test1.qrc
    To copy to clipboard, switch view to plain text mode 

    Thanks to anyone who can help in this mater.

    Sergio

    and, finally, the mainwindow.cpp:

    I attached it to this post because this forum allows only code with less than 10,000 chars.
    Attached Files Attached Files

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: One dialog for several lcdnumber values?

    QSignalMapper is designed for this sort of thing.

  3. #3
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: One dialog for several lcdnumber values?

    Quote Originally Posted by ssaguiar View Post
    The problem i sthat I have to create one QDialog for each of the tanks because the slot() don't accept a value in it's call.
    No, but in the slot you can use sender() to find out the object that sent the signal, or use QSignalMapper to map the object reference to a id (such as an integer). You can then use this id to reference into an array, for example.

  4. #4
    Join Date
    Apr 2011
    Posts
    9
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: One dialog for several lcdnumber values?

    Ok, thanks.
    I will study it and try to implement.

    Sergio

  5. #5
    Join Date
    Apr 2011
    Posts
    9
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: One dialog for several lcdnumber values?

    Ok, Let's see what I have done...

    In mainwindow.h, I added this:

    Qt Code:
    1. #include <QSignalMapper>
    2. .
    3. .
    4. .
    5. and
    6. .
    7. .
    8. private slots:
    9. .
    10. id View_tank_Details(QString local);
    To copy to clipboard, switch view to plain text mode 

    In my mainwindow.ccp I have implemented this code:

    Qt Code:
    1. .
    2. .
    3. QSignalMapper *signalMapper;
    4. signalMapper = new QSignalMapper(this);
    5. .
    6. .
    7.  
    8.  
    9.  
    10. View_tank1 = new QPushButton( "Tank1", this );
    11. View_tank1->setFlat(true);
    12. View_tank1->setIcon (ButtonIcon);
    13. //View_tank1->setFixedSize(16,16);
    14. View_tank1->setGeometry( QRect( 160, 10, 16, 16 ));
    15. View_tank1->setCursor(Qt::ArrowCursor);
    16. connect(View_tank1, SIGNAL(clicked()), signalMapper, SLOT(map()));
    17. signalMapper->setMapping(View_tank1, View_tank1->text());
    18.  
    19.  
    20. View_tank2 = new QPushButton( "Tank2", this );
    21. View_tank2->setFlat(true);
    22. View_tank2->setIcon (ButtonIcon);
    23. //View_tank2->setFixedSize(16,16);
    24. View_tank2->setGeometry( QRect( 350, 10, 16, 16 ));
    25. View_tank2->setCursor(Qt::ArrowCursor);
    26. connect(View_tank2, SIGNAL(clicked()), signalMapper, SLOT(map()));
    27. signalMapper->setMapping(View_tank2, View_tank2->text());
    28.  
    29. View_tank3 = new QPushButton( "Tank3", this );
    30. View_tank3->setFlat(true);
    31. View_tank3->setIcon (ButtonIcon);
    32. //View_tank3->setFixedSize(16,16);
    33. View_tank3->setGeometry( QRect( 550, 10, 16, 16 ));
    34. View_tank3->setCursor(Qt::ArrowCursor);
    35. connect(View_tank3, SIGNAL(clicked()), signalMapper, SLOT(map()));
    36. signalMapper->setMapping(View_tank3, View_tank3->text());
    37.  
    38. View_tank4 = new QPushButton( "Tank4", this );
    39. View_tank4->setFlat(true);
    40. View_tank4->setIcon (ButtonIcon);
    41. //View_tank4->setFixedSize(16,16);
    42. View_tank4->setGeometry( QRect( 760, 10, 16, 16 ));
    43. View_tank4->setCursor(Qt::ArrowCursor);
    44. connect(View_tank4, SIGNAL(clicked()), signalMapper, SLOT(map()));
    45. signalMapper->setMapping(View_tank4, View_tank4->text());
    46.  
    47. View_tank5 = new QPushButton( "Tank5", this );
    48. View_tank5->setFlat(true);
    49. View_tank5->setIcon (ButtonIcon);
    50. //View_tank5->setFixedSize(16,16);
    51. View_tank5->setGeometry( QRect( 160, 110, 16, 16 ));
    52. View_tank5->setCursor(Qt::ArrowCursor);
    53. connect(View_tank5, SIGNAL(clicked()), signalMapper, SLOT(map()));
    54. signalMapper->setMapping(View_tank5, View_tank5->text());
    55.  
    56. View_tank6 = new QPushButton( "Tank6", this );
    57. View_tank6->setFlat(true);
    58. View_tank6->setIcon (ButtonIcon);
    59. //View_tank6->setFixedSize(16,16);
    60. View_tank6->setGeometry( QRect( 350, 110, 16, 16 ));
    61. View_tank6->setCursor(Qt::ArrowCursor);
    62. connect(View_tank6, SIGNAL(clicked()), signalMapper, SLOT(map()));
    63. signalMapper->setMapping(View_tank6, View_tank6->text());
    64.  
    65. View_tank7 = new QPushButton( "Tank7", this );
    66. View_tank7->setFlat(true);
    67. View_tank7->setIcon (ButtonIcon);
    68. //View_tank7->setFixedSize(16,16);
    69. View_tank7->setGeometry( QRect( 550, 110, 16, 16 ));
    70. View_tank7->setCursor(Qt::ArrowCursor);
    71. connect(View_tank7, SIGNAL(clicked()), signalMapper, SLOT(map()));
    72. signalMapper->setMapping(View_tank7, View_tank7->text());
    73.  
    74. View_tank8 = new QPushButton( "Tank8", this );
    75. View_tank8->setFlat(true);
    76. View_tank8->setIcon (ButtonIcon);
    77. //View_tank8->setFixedSize(16,16);
    78. View_tank8->setGeometry( QRect( 760, 110, 16, 16 ));
    79. View_tank8->setCursor(Qt::ArrowCursor);
    80. connect(View_tank8, SIGNAL(clicked()), signalMapper, SLOT(map()));
    81. signalMapper->setMapping(View_tank8, View_tank8->text());
    82.  
    83. View_tank9 = new QPushButton( "Tank9", this );
    84. View_tank9->setFlat(true);
    85. View_tank9->setIcon (ButtonIcon);
    86. //View_tank9->setFixedSize(16,16);
    87. View_tank9->setGeometry( QRect( 160, 210, 16, 16 ));
    88. View_tank9->setCursor(Qt::ArrowCursor);
    89. connect(View_tank9, SIGNAL(clicked()), signalMapper, SLOT(map()));
    90. signalMapper->setMapping(View_tank9, View_tank9->text());
    91.  
    92. View_tank10 = new QPushButton( "Tank10", this );
    93. View_tank10->setFlat(true);
    94. View_tank10->setIcon (ButtonIcon);
    95. //View_tank10->setFixedSize(16,16);
    96. View_tank10->setGeometry( QRect( 350, 210, 16, 16 ));
    97. View_tank10->setCursor(Qt::ArrowCursor);
    98. connect(View_tank10, SIGNAL(clicked()), signalMapper, SLOT(map()));
    99. signalMapper->setMapping(View_tank10, View_tank10->text());
    100.  
    101. View_tank11 = new QPushButton( "Tank11", this );
    102. View_tank11->setFlat(true);
    103. View_tank11->setIcon (ButtonIcon);
    104. //View_tank11->setFixedSize(16,16);
    105. View_tank11->setGeometry( QRect( 550, 210, 16, 16 ));
    106. View_tank11->setCursor(Qt::ArrowCursor);
    107. connect(View_tank11, SIGNAL(clicked()), signalMapper, SLOT(map()));
    108. signalMapper->setMapping(View_tank11, View_tank11->text());
    109.  
    110. View_tank12 = new QPushButton( "Tank12", this );
    111. View_tank12->setFlat(true);
    112. View_tank12->setIcon (ButtonIcon);
    113. //View_tank12->setFixedSize(16,16);
    114. View_tank12->setGeometry( QRect( 760, 210, 16, 16 ));
    115. View_tank12->setCursor(Qt::ArrowCursor);
    116. connect(View_tank12, SIGNAL(clicked()), signalMapper, SLOT(map()));
    117. signalMapper->setMapping(View_tank12, View_tank12->text());
    118.  
    119. View_tank13 = new QPushButton( "Tank13", this );
    120. View_tank13->setFlat(true);
    121. View_tank13->setIcon (ButtonIcon);
    122. //View_tank13->setFixedSize(16,16);
    123. View_tank13->setGeometry( QRect( 160, 310, 16, 16 ));
    124. View_tank13->setCursor(Qt::ArrowCursor);
    125. connect(View_tank13, SIGNAL(clicked()), signalMapper, SLOT(map()));
    126. signalMapper->setMapping(View_tank13, View_tank13->text());
    127.  
    128. View_tank14 = new QPushButton( "Tank14", this );
    129. View_tank14->setFlat(true);
    130. View_tank14->setIcon (ButtonIcon);
    131. //View_tank14->setFixedSize(16,16);
    132. View_tank14->setGeometry( QRect( 350, 310, 16, 16 ));
    133. View_tank14->setCursor(Qt::ArrowCursor);
    134. connect(View_tank14, SIGNAL(clicked()), signalMapper, SLOT(map()));
    135. signalMapper->setMapping(View_tank14, View_tank14->text());
    136.  
    137. View_tank15 = new QPushButton( "Tank15", this );
    138. View_tank15->setFlat(true);
    139. View_tank15->setIcon (ButtonIcon);
    140. View_tank15->setGeometry( QRect( 550, 310, 16, 16 ));
    141. View_tank15->setCursor(Qt::ArrowCursor);
    142. connect(View_tank15, SIGNAL(clicked()), signalMapper, SLOT(map()));
    143. signalMapper->setMapping(View_tank15, View_tank15->text());
    144.  
    145. View_tank16 = new QPushButton( "Tank16", this );
    146. View_tank16->setFlat(true);
    147. View_tank16->setIcon (ButtonIcon);
    148. View_tank16->setGeometry( QRect( 760, 310, 16, 16 ));
    149. View_tank16->setCursor(Qt::ArrowCursor);
    150. connect(View_tank16, SIGNAL(clicked()), signalMapper, SLOT(map()));
    151. signalMapper->setMapping(View_tank16, View_tank16->text());
    152.  
    153. connect(signalMapper, SIGNAL(mapped(QString)), this, SLOT(View_tank_Details(QString)));
    To copy to clipboard, switch view to plain text mode 

    And, to test, I have implemented the View_tank_details as:

    Qt Code:
    1. void MainWindow::View_tank_Details(QString local)
    2. {
    3.  
    4. QMessageBox msgBox;
    5. msgBox.setIcon(QMessageBox::Warning);
    6. msgBox.setText(local);
    7. msgBox.setStandardButtons(QMessageBox::Ok);
    8. msgBox.setDefaultButton(QMessageBox::Ok);
    9. msgBox.exec();
    To copy to clipboard, switch view to plain text mode 

    Now, I will implement a routine to generate the QPushButton in a loop and attach the index of them to the slot, because, as I have done, using the button text, I have lost the button's image (the image can't be seen, just the text).

    Now, I wish to know how can I call the dialog class, wich is implemented in dialog1.ccp file this way:

    Qt Code:
    1. #include "mainwindow.h"
    2. #include <dialog1.h>
    3.  
    4. Dialog::Dialog( QWidget* Parent, Qt::WFlags Flags ) : QDialog( Parent, Flags )
    5. {
    6. setWindowTitle( tr( "Tanque 1" ) );
    7. resize( QSize(800, 480).expandedTo(minimumSizeHint()) );
    8. setWindowFlags(this->windowFlags() & Qt::Window | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint);
    9. this->setStyleSheet( "background-image: url(:/images/background_main.png)");
    10.  
    11. QPushButton *Button = new QPushButton( tr( "ok" ), this );
    12. QLCDNumber *Tanque1Level = new QLCDNumber(5, this);
    13.  
    14. Tanque1Level->setGeometry( 10, 10, 180, 80 );
    15. Tanque1Level->setSmallDecimalPoint( false );
    16. Tanque1Level->setNumDigits( 5 );
    17. Tanque1Level->setSegmentStyle(QLCDNumber::Flat);
    18. Tanque1Level->setFrameShape(QLCDNumber::Box);
    19. Tanque1Level->setFrameShadow(QLCDNumber::Sunken);
    20. Tanque1Level->setMode(QLCDNumber::Dec);
    21. Tanque1Level->setStyleSheet("background: transparent;color:rgb(0,255,0); border: 2px solid grey;");
    22. Tanque1Level->display(12976);
    23.  
    24. Button->setGeometry( QRect( 750, 440, 40, 30 ) );
    25. connect( Button, SIGNAL( clicked() ), this, SLOT( close() ) );
    26.  
    27. }
    To copy to clipboard, switch view to plain text mode 

    Thanks to all for your help.

    Just one more observation:

    If I could intercept (if it existed) the event onclick over the lcd numbers, I could not use the buttons to call the View_tank_Details.
    Is there any idea about this aproach?

    Thanks again.

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: One dialog for several lcdnumber values?

    Sounds like you want to override the default (do-nothing) QWidget::mousePressEvent()
    Qt Code:
    1. #include <QtGui>
    2. #include <QDebug>
    3.  
    4. class MyLCDNumber: public QLCDNumber {
    5. Q_OBJECT
    6. public:
    7. MyLCDNumber(QWidget *p = 0): QLCDNumber(p) {
    8. }
    9. protected:
    10. void mousePressEvent(QMouseEvent *event) {
    11. qDebug() << "mousePressEvent received";
    12. int val = intValue();
    13. display(++val);
    14. event->accept();
    15. }
    16. };
    17.  
    18. int main(int argc, char *argv[])
    19. {
    20. QApplication app(argc, argv);
    21.  
    22. MyLCDNumber n;
    23. n.setGeometry(100, 100, 100, 50);
    24. n.display(23);
    25. n.show();
    26. return app.exec();
    27. }
    28. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Apr 2011
    Posts
    9
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: One dialog for several lcdnumber values?

    Ok, I got how to make my dialog work, receiving the text from the main window (as I posted before, thanks to all my friends who helped).

    To create the dialog, I use this code:
    Qt Code:
    1. void MainWindow::View_tank_Details(QString local)
    2. {
    3.  
    4. QDialog *Tank_Details = new QDialog();
    5. QPushButton *Button = new QPushButton( tr( "ok" ), Tank_Details);
    6. QLCDNumber *Tanque1Level = new QLCDNumber(5, Tank_Details );
    7.  
    8. Tank_Details->setWindowFlags(Tank_Details->windowFlags() & Qt::Window | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint);
    9. Tank_Details->setGeometry(x,y,800,480);
    10. Tank_Details->show();
    11. Tank_Details->activateWindow();
    12. Tank_Details->setStyleSheet( "background-image: url(:/images/background_main.png)");
    13.  
    14. Tanque1Level->setGeometry( 10, 10, 180, 80 );
    15. Tanque1Level->setSmallDecimalPoint( false );
    16. Tanque1Level->setNumDigits( 5 );
    17. Tanque1Level->setSegmentStyle(QLCDNumber::Flat);
    18. Tanque1Level->setFrameShape(QLCDNumber::Box);
    19. Tanque1Level->setFrameShadow(QLCDNumber::Sunken);
    20. Tanque1Level->setMode(QLCDNumber::Dec);
    21. Tanque1Level->setStyleSheet("background: transparent;color:rgb(0,255,0); border: 2px solid grey;");
    22. Tanque1Level->display(12976);
    23.  
    24. Button->setGeometry( QRect( 750, 440, 40, 30 ) );
    25. connect( Button, SIGNAL( clicked() ), Tank_Details, SLOT( close() ) );
    26. }
    To copy to clipboard, switch view to plain text mode 

    Now, it seems to work well.
    I just have to make it work even when user clicks over the lcd numbers or when he clicks over the buttons (without loosing the image of the button, as it's now).

    Cheers

  8. #8
    Join Date
    Apr 2011
    Posts
    9
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: One dialog for several lcdnumber values?

    Ok, got it to work.

    mainwindow.cpp:

    Qt Code:
    1. .
    2. .
    3. QSignalMapper *signalMapper= new QSignalMapper(this);
    4. .
    5. .
    6.  
    7. View_tank1 = new QPushButton( "", this );
    8. View_tank1->setFlat(true);
    9. View_tank1->setIcon (ButtonIcon);
    10. View_tank1->setGeometry( QRect( 160, 10, 16, 16 ));
    11. View_tank1->setCursor(Qt::ArrowCursor);
    12. View_tank1->setObjectName("Tanque_1");
    13. View_tank1->setCursor(Qt::OpenHandCursor);
    14. View_tank1->setStatusTip(tr("Detalhes do tanque."));
    15. connect(View_tank1, SIGNAL(clicked()), signalMapper, SLOT(map()));
    16. signalMapper->setMapping(View_tank1, View_tank1->objectName());// ->text());
    17.  
    18. View_tank2 = new QPushButton( "", this );
    19. View_tank2->setFlat(true);
    20. View_tank2->setIcon (ButtonIcon);
    21. View_tank2->setGeometry( QRect( 350, 10, 16, 16 ));
    22. View_tank2->setCursor(Qt::ArrowCursor);
    23. View_tank2->setObjectName("Tanque_2");
    24. View_tank2->setCursor(Qt::OpenHandCursor);
    25. connect(View_tank2, SIGNAL(clicked()), signalMapper, SLOT(map()));
    26. signalMapper->setMapping(View_tank2, View_tank2->objectName());
    27. .
    28. .
    29. .
    30. .
    31. View_tank15 = new QPushButton( "", this );
    32. View_tank15->setFlat(true);
    33. View_tank15->setIcon (ButtonIcon);
    34. View_tank15->setGeometry( QRect( 550, 340, 16, 16 ));
    35. View_tank15->setCursor(Qt::ArrowCursor);
    36. View_tank15->setObjectName("Tanque_15");
    37. View_tank15->setCursor(Qt::OpenHandCursor);
    38. connect(View_tank15, SIGNAL(clicked()), signalMapper, SLOT(map()));
    39. signalMapper->setMapping(View_tank15, View_tank15->objectName());
    40.  
    41. View_tank16 = new QPushButton( "", this );
    42. View_tank16->setFlat(true);
    43. View_tank16->setIcon (ButtonIcon);
    44. View_tank16->setGeometry( QRect( 760, 340, 16, 16 ));
    45. View_tank16->setCursor(Qt::ArrowCursor);
    46. View_tank16->setObjectName("Tanque_16");
    47. View_tank16->setCursor(Qt::OpenHandCursor);
    48. connect(View_tank16, SIGNAL(clicked()), signalMapper, SLOT(map()));
    49. signalMapper->setMapping(View_tank16, View_tank16->objectName());
    50.  
    51. connect(signalMapper, SIGNAL(mapped(QString)), this, SLOT(View_tank_Details(QString)));
    52. .
    53. .
    54. .
    55. void MainWindow::View_tank_Details(QString local)
    56. {
    57.  
    58. QIcon ico;
    59. ico.addPixmap(QPixmap(":/images/exit-2.svg"), QIcon::Normal, QIcon::On);
    60. ico.addPixmap(QPixmap(":/images/exit.svg"), QIcon::Normal, QIcon::Off);
    61.  
    62. QDialog *Tank_Details = new QDialog();
    63. QLabel *GraphPlot = new QLabel(Tank_Details);
    64. QLabel *GraphTitle = new QLabel(Tank_Details);
    65. QPushButton *ExitButton = new QPushButton("", GraphTitle);
    66. QLCDNumber *Tanque1Level = new QLCDNumber(5, GraphTitle );
    67.  
    68. Tank_Details->setWindowFlags(Tank_Details->windowFlags() & Qt::Window | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint);
    69. Tank_Details->setGeometry(x,y,800,480);
    70. Tank_Details->show();
    71. Tank_Details->activateWindow();
    72. Tank_Details->setStyleSheet( "background-image: url(:/images/background_main.png)");
    73.  
    74. Tanque1Level->setGeometry( 10, 5, 180, 50 );
    75. Tanque1Level->setSmallDecimalPoint( false );
    76. Tanque1Level->setNumDigits( 5 );
    77. Tanque1Level->setSegmentStyle(QLCDNumber::Flat);
    78. Tanque1Level->setFrameShape(QLCDNumber::NoFrame);
    79. Tanque1Level->setFrameShadow(QLCDNumber::Plain);
    80. Tanque1Level->setMode(QLCDNumber::Dec);
    81. Tanque1Level->setStyleSheet("background: transparent;color:rgb(0,255,0); border: 0px;");
    82. Tanque1Level->display(12976);
    83.  
    84. GraphTitle->setGeometry(10, 20, 780, 60);
    85. //set font
    86. QFont font;
    87. font.setPointSize(32);
    88. font.setBold(true);
    89. GraphTitle->setFont(font);
    90. GraphTitle->setAutoFillBackground(true);
    91. GraphTitle->setAlignment( Qt::AlignCenter );
    92. GraphTitle->setFrameStyle( QFrame::Panel | QFrame::Raised );
    93. GraphTitle->setStyleSheet("color:rgb(255,255,255);border: 1px solid grey;");
    94. GraphTitle->setText(local);
    95.  
    96. GraphPlot->setGeometry(10, 90, 780, 380);
    97. GraphPlot->setStyleSheet("border: 1px solid grey;");
    98.  
    99. ExitButton->setIcon(QIcon(ico));
    100. ExitButton->setText(tr(""));
    101. ExitButton->setFlat(true);
    102. ExitButton->setIconSize(QSize(32,32));
    103. ExitButton->setGeometry( QRect( 740, 14, 32, 32));
    104. ExitButton->setCursor(Qt::OpenHandCursor);
    105. ExitButton->setStyleSheet("background: transparent;border: 0px;");
    106.  
    107. connect( ExitButton, SIGNAL( clicked() ), Tank_Details, SLOT( close() ) );
    108.  
    109. }
    To copy to clipboard, switch view to plain text mode 

    Now, I want to plot 2D data in the QLabel GraphPlot, but, as it's created dinamically, I don't know where I can put the paintEvent.

    I will start a new thread asking the question about the 2D plot.

    Thanks to all who helped me.

Similar Threads

  1. How to access objects of parent Dialog from Child Dialog .
    By ranjit.kadam in forum Qt Programming
    Replies: 4
    Last Post: 18th April 2011, 06:39
  2. Problem with view on LCDNumber
    By Danny Fan in forum Newbie
    Replies: 1
    Last Post: 13th March 2011, 09:31
  3. closing child dialog closes parent dialog
    By sparticus_37 in forum Newbie
    Replies: 2
    Last Post: 28th May 2010, 19:46
  4. How to blur parent dialog when child dialog is displayed
    By abhilashajha in forum Qt Programming
    Replies: 4
    Last Post: 10th June 2009, 13:01
  5. Replies: 3
    Last Post: 20th April 2006, 11:21

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.