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:
Code:
mainwindow::mainwindow()
{
m_Central->setLayout(m_layout);
m_carto = new GLWidget
m_carto->displayRedTriangle();
m_layout->addwidget(carto);
setCentralWidget(m_Central);
}
glwidget.cpp:
Code:
void GLWidget::paintGL()
{
// some initializing boring parameters
// Setting displayRedTriangle() here will show the red triangle in the user interface.
}
void GLWidget::displayRedTriangle()
{
glBegin(GL_TRIANGLES)
glColor3f(1.0f,0.0f,0.0f)
glVertex3i(-1,0,2);
glVertex3i(1,0,2);
glVertex3i(0,0,0);
glEnd();
}
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
Re: call drawing function out of paintGL
Why do you want to do that?
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
Re: call drawing function out of paintGL
So just call update() and draw that cursor as part of paintGL().
Re: call drawing function out of paintGL
Ho yes, yes, I thought of it at the first time. I set it like this:
Code:
mainwindow::mainwindow()
{
m_Central->setLayout(m_layout);
m_carto = new GLWidget
m_carto->displayRedTriangle();
m_carto->updateGL();
m_layout->addwidget(carto);
setCentralWidget(m_Central);
}
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
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.
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 :'(
Re: call drawing function out of paintGL
Quote:
Originally Posted by
CyrilQt
I want to display as much cursor that the user wishes
So store a list of coordinates.
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!!
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
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.
Code:
#include <QtGui>
Q_OBJECT
public:
Entry e;
e.label = label;
e.pos = pos;
QRect r
= fm.
boundingRect(label
);
r.translate(e.pos);
e.boundingBox = r;
e.selected = false;
m_entries << e;
update();
}
void removeEntry(int which) {
m_entries.removeAt(which);
update();
}
int indexAt
(QPoint pos
) const { for(int i=0; i< m_entries.count(); ++i) {
const Entry &e = m_entries.at(i);
if(e.boundingBox.contains(pos))
return i;
}
return -1;
}
protected:
foreach(Entry e, m_entries) {
p.save();
if(e.selected) {
p.setPen(Qt::red);
}
p.drawText(e.pos, e.label);
p.restore();
// p.save();
// p.setPen(Qt::red);
// p.drawRect(e.boundingBox);
// p.restore();
}
}
int idx = indexAt(me->pos());
if(idx < 0) return;
m_entries[idx].selected = !m_entries[idx].selected;
update();
}
private:
struct Entry {
bool selected;
};
QList<Entry> m_entries;
};
#include "main.moc"
int main(int argc, char **argv) {
Widget w;
w.show();
w.
addEntry("Home",
QPoint(100,
100));
w.
addEntry("School",
QPoint(300,
200));
w.
addEntry("Work",
QPoint(500,
20));
return app.exec();
}
Re: call drawing function out of paintGL
Thanks!!
I will try this tomorrow,
I understood part of the code and see how it may work *hope*
:)
Re: call drawing function out of paintGL
Hi,
I'm getting some good results due to your advice. I will write it back soon, it may help someone later.