Results 1 to 13 of 13

Thread: call drawing function out of paintGL

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2012
    Posts
    15
    Thanks
    7
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default call drawing function out of paintGL

    Hi all,
    Here, I joined a QGLWidget class QGLWidget in a main window. The glwidget displays well what is contained in the method paintGL ().
    But I want to ensure that these methods, those contained in paintGL, are called from the mainwindows by the user according to his need to display.
    Here are bits of code most relevant to get an idea of the situation:

    mainwindow.cpp:
    Qt Code:
    1. mainwindow::mainwindow()
    2. {
    3. m_Central= new QWidget;
    4. m_layout = new QGridLayout;
    5. m_Central->setLayout(m_layout);
    6.  
    7. m_carto = new GLWidget
    8. m_carto->displayRedTriangle();
    9. m_layout->addwidget(carto);
    10.  
    11. setCentralWidget(m_Central);
    12. }
    To copy to clipboard, switch view to plain text mode 

    glwidget.cpp:
    Qt Code:
    1. void GLWidget::paintGL()
    2. {
    3. // some initializing boring parameters
    4. // Setting displayRedTriangle() here will show the red triangle in the user interface.
    5. }
    6.  
    7. void GLWidget::displayRedTriangle()
    8. {
    9. glBegin(GL_TRIANGLES)
    10. glColor3f(1.0f,0.0f,0.0f)
    11. glVertex3i(-1,0,2);
    12. glVertex3i(1,0,2);
    13. glVertex3i(0,0,0);
    14. glEnd();
    15. }
    To copy to clipboard, switch view to plain text mode 

    So the question is, how to use and make work the displayRedTriangle() from any place that is not directly paintGL?
    Thanks for your help,
    Best regards.

    Cyril

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: call drawing function out of paintGL

    Why do you want to do that?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    May 2012
    Posts
    15
    Thanks
    7
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: call drawing function out of paintGL

    good evening,

    This triangle is a kind of cursor to set on a map at a perticular position.
    I have the map ( i used a .mnt and a .tga pictures for the texture) and til this point everything is fine.
    My user interface built, in the mainwindows ask users to enter new datas linked with a postgresql database. One of the table contains the coordinates of other items like adresses etc...
    I would like to call them (the cursors through a function for each display preferences of the users) this cursor should be called by a user, and displayed at the correct position. I would like to be able to add points from the UI i built and see them on the map at the same time...
    I thanks you for your attention, and hope to find a solution.
    Best regards.

    Cyril
    Last edited by CyrilQt; 13th June 2012 at 18:38.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: call drawing function out of paintGL

    So just call update() and draw that cursor as part of paintGL().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    May 2012
    Posts
    15
    Thanks
    7
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: call drawing function out of paintGL

    Ho yes, yes, I thought of it at the first time. I set it like this:
    Qt Code:
    1. mainwindow::mainwindow()
    2. {
    3. m_Central= new QWidget;
    4. m_layout = new QGridLayout;
    5. m_Central->setLayout(m_layout);
    6.  
    7. m_carto = new GLWidget
    8. m_carto->displayRedTriangle();
    9. m_carto->updateGL();
    10. m_layout->addwidget(carto);
    11.  
    12. setCentralWidget(m_Central);
    13. }
    To copy to clipboard, switch view to plain text mode 

    but it didn't work...or it works, but I can see nothing, no changes.

    I thank you for your reply and proposal, I'm really short of idea though i guess it's not a so difficult problem. Maybe should i have post it in the newbies forum?

    Cyril

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: call drawing function out of paintGL

    No, that's wrong. You should store the coordinates for the triangle, then call update() and then in paintGL() use those stored coordinates to draw that triangle.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    May 2012
    Posts
    15
    Thanks
    7
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: call drawing function out of paintGL

    No, I'm really sorry but I do not understand.
    I may have wanted to be too concise, or I have not explained my problem clearly.
    I want to display as much cursor that the user wishes, as it can have the choice to withdraw according to the elements he wants to view.
    To this, I thought to set the function into a slot displayRedtriangle issued by a signal such as those emitted by QCheckBox.
    For this I thought I would call the function as Defois triangle as necessary, and display all those that the user wishes.
    I should have the wrong path :'(

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: call drawing function out of paintGL

    Quote Originally Posted by CyrilQt View Post
    I want to display as much cursor that the user wishes
    So store a list of coordinates.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. The following user says thank you to wysota for this useful post:

    CyrilQt (13th June 2012)

  10. #9
    Join Date
    May 2012
    Posts
    15
    Thanks
    7
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: call drawing function out of paintGL

    Ok, i will try something like that
    but i'm not sure how to proceed, we will see
    thanks!!

  11. #10
    Join Date
    May 2012
    Posts
    15
    Thanks
    7
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: call drawing function out of paintGL

    I feel very sorry, but I didn't find what you try to explain me.
    I stored all my points in a table, and i'm able to display all of them setting the relevant function showMyTriangles ( 3dPoints*tab) in PaintGL().
    All points are loaded and display.
    But i cannot have any interaction with it from the mainwindow interface. For instance, i would like to display my house and my school, and have only two triangles. As well I would like to make them disapear with the appropriate Qcheckbox.
    I'm really in need, and i really tried my best with your indications.
    Best regards.

    Cyril

  12. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: call drawing function out of paintGL

    Here is a simple example, adapt it to your needs. I'm not commenting it on purpose so that you have to put some effort in understanding it.

    Qt Code:
    1. #include <QtGui>
    2.  
    3. class Widget : public QWidget {
    4. Q_OBJECT
    5. public:
    6. Widget(QWidget *parent = 0) : QWidget(parent) {}
    7. void addEntry(QString label, QPoint pos) {
    8. Entry e;
    9. e.label = label;
    10. e.pos = pos;
    11. QFontMetrics fm = fontMetrics();
    12. QRect r = fm.boundingRect(label);
    13. r.translate(e.pos);
    14. e.boundingBox = r;
    15. e.selected = false;
    16. m_entries << e;
    17. update();
    18. }
    19.  
    20. void removeEntry(int which) {
    21. m_entries.removeAt(which);
    22. update();
    23. }
    24.  
    25. int indexAt(QPoint pos) const {
    26. for(int i=0; i< m_entries.count(); ++i) {
    27. const Entry &e = m_entries.at(i);
    28. if(e.boundingBox.contains(pos))
    29. return i;
    30. }
    31. return -1;
    32. }
    33. protected:
    34. void paintEvent(QPaintEvent *pe) {
    35. QPainter p(this);
    36. foreach(Entry e, m_entries) {
    37. p.save();
    38. if(e.selected) {
    39. p.setPen(Qt::red);
    40. }
    41. p.drawText(e.pos, e.label);
    42. p.restore();
    43. // p.save();
    44. // p.setPen(Qt::red);
    45. // p.drawRect(e.boundingBox);
    46. // p.restore();
    47. }
    48. }
    49. void mouseReleaseEvent(QMouseEvent *me) {
    50. int idx = indexAt(me->pos());
    51. if(idx < 0) return;
    52. m_entries[idx].selected = !m_entries[idx].selected;
    53. update();
    54. }
    55.  
    56. private:
    57. struct Entry {
    58. QString label;
    59. QPoint pos;
    60. QRect boundingBox;
    61. bool selected;
    62. };
    63.  
    64. QList<Entry> m_entries;
    65. };
    66.  
    67.  
    68. #include "main.moc"
    69.  
    70. int main(int argc, char **argv) {
    71. QApplication app(argc, argv);
    72. Widget w;
    73. w.show();
    74. w.addEntry("Home", QPoint(100, 100));
    75. w.addEntry("School", QPoint(300, 200));
    76. w.addEntry("Work", QPoint(500, 20));
    77. return app.exec();
    78. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. The following user says thank you to wysota for this useful post:

    CyrilQt (14th June 2012)

Similar Threads

  1. Replies: 1
    Last Post: 11th December 2011, 08:07
  2. to call member function
    By vinayaka in forum General Programming
    Replies: 5
    Last Post: 1st July 2011, 13:48
  3. Replies: 7
    Last Post: 1st July 2011, 01:21
  4. Qt function call in vb.net
    By abghosh in forum Qt Programming
    Replies: 7
    Last Post: 6th March 2010, 17:00
  5. function call
    By Walsi in forum Qt Programming
    Replies: 3
    Last Post: 12th June 2007, 09:13

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.