QPaint Class and QGraphicsScene ....I am stuck !!
Hi,
I have written a program to show some buttons and use QGraphicsscene and paint class but when i run this program the output is only a 'WHITE BLANK SCREEN '
Below is the implementation of this class and main function,any help/suggestion would be welcome.....pls give it a look !!
Code:
int main(int argc,char *argv[])
{
paintClass paint;
paint.addScene();
paint.setIcons();
paint.drawBGround();
paint.show();
return app.exec();
}
Code:
#ifndef PAINTCLASS_H
#define PAINTCLASS_H
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QGraphicsItem>
#include <QGraphicsEllipseItem>
#include <QCursor>
#include <QRectF>
#include <QPushButton>
#include <QGraphicsProxyWidget>
#include <QIcon>
#include <QVBoxLayout>
#include <QPainter>
#include <QWidget>
{
public:
QGraphicsProxyWidget *proxy;
void drawBGround();
void addScene();
void setIcons();
};
#endif
Code:
#include "paintClass.h"
{
r1.setRect(100,200,100,160);
r2.setRect(0,0,300,300);
}
void paintClass::drawBGround()
{
painter.setPen(Qt::black);
scene.addText("Hello, world!");
scene.setBackgroundBrush(Qt::blue);
}
void paintClass::addScene()
{
scene.addText("Hello, world!");
hLayout->addWidget(stopButton);
hLayout->addWidget(playButton);
widg->setLayout(hLayout);
scene.addWidget(widg);
}
void paintClass::setIcons()
{
playButton
->setIcon
(QIcon("./pics/play.JPG"));
stopButton
->setIcon
(QIcon("./pics/stop.JPG"));
}
Re: QPaint Class and QGraphicsScene ....I am stuck !!
The code above is not very well structured. It almost looks like you are randomly trying things. You should start with going through the Qt tutorial. Then, you can take a look at graphics view examples.
Re: QPaint Class and QGraphicsScene ....I am stuck !!
There is a new Graphics View webcast from ICS Network. It is available for viewing online, or video download. You can find it at: <http://www.ics.com/icsnetwork/>. There is also a brand new thread for the webcast here at QtCenter: <http://www.qtcentre.org/forum/f-icsnetwork-25.html>.
This is a good place to start learning about Qt's Graphics View framework, starting with a simple "hello world" program and advancing to animation and optimization.
Re: QPaint Class and QGraphicsScene ....I am stuck !!
Hi..
thanks for the reply ..i have just starting streaming the video..i hope it would be helpful...any ways ,the problem with this code is more with the class structure i think (as mentioned by jpn ),initialy i was trying these things in the main function and all was working nice but then i had to use QT'S drawBackground() function which is virtual and protected so i had to create a class in which i could be using it...so...the code in main which looks like this works fine...
Code:
#include <QApplication>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QGraphicsItem>
#include <QGraphicsEllipseItem>
#include <QCursor>
#include <QRectF>
#include <QPushButton>
#include <QGraphicsProxyWidget>
#include <QIcon>
#include <QVBoxLayout>
#include <QPainter>
#include "paintClass.h"
int main(int argc,char *argv[])
{
const QRectF r1
(100,
200,
100,
160);
ellipseItem.setSelected(true);
ellipseItem.setVisible(true);
scene.addItem(&ellipseItem);
scene.addText("Hello, world!");
stopButton
->setIcon
(QIcon("C:/pics/stop.JPG"));
playButton
->setIcon
(QIcon("C:/pics/play.JPG"));
hLayout->addWidget(stopButton);
hLayout->addWidget(playButton);
widg->setLayout(hLayout);
QGraphicsProxyWidget *proxy = scene.addWidget(widg);
paintClass *paint ;
paint->drawBGround(&scene);
view.show();
return app.exec();
}
..and in my first post the code is almost same except that (i think so )the class is not properly called...any advice would be welcomed...thanks again ...!!1
Re: QPaint Class and QGraphicsScene ....I am stuck !!
Quote:
Originally Posted by
salmanmanekia
the code in main which looks like this works fine...
Code:
paintClass *paint ;
paint->drawBGround(&scene);
Are you sure? :)
Re: QPaint Class and QGraphicsScene ....I am stuck !!
sorry man ...i forgot to comment it...!!...you know , for now there is no paintClass ..so ...
// 1. paintClass *paint ;
// 2. paint->drawBGround(&scene);
and everything works fine....:)
Re: QPaint Class and QGraphicsScene ....I am stuck !!
So, have you looked at graphics view examples and did you see the webcast as proposed? It makes no sense inherit something from QPainter and QGraphicsView. Also, writing something like:
has no effect at all. The QGraphicsView object gets immediately destructed, according to normal C++ rules.
I would recommend taking one of the graphics view examples as a base. That would give you a properly constructed base where you can start adding your own things.
Re: QPaint Class and QGraphicsScene ....I am stuck !!
yes i have taken look at webcast ....what i think is that ,that i can understand the graphic related api in qt,the problem lies in how to manage classes ,in this case its graphics ...it could have been a network related api and i would have the same problem...
still i understand that this statement executes and ends at the same time...so no effect at all
1. {
2. ...
3. QGraphicsView view(&scene);
4. }
can you guide me to some good resource/tutorial for the class heirachy like how inheritance works in qt ...also if you can pinpoint the wrong things/concept which i have in my code ,so that i can look into solution to that..!!!!..because i am still not crystal clear that wht the problem is what exactly is the way to solve it...thanks again....