-2

i'm very newbie and lost! I have a .cpp file in my qt project and my own widget.cpp wich has drawings! Now i want to get the data from the other .cpp file, from a class called, outputtext..which has a method add(name,value) both std string!

Know i want in my widget.cpp to import this stings! I have a form and i put a button on it 'get string'-button! Know i have

void Widget::on_pushButton_clicked(){
// how can i use Qpainter to deaw the text in my widget?

}

so, this is my widget class:

#include "widget.h"
#include "ui_widget.h"
#include "outputtext.h"

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}



void Widget::on_pushButton_clicked()
{

 //int outputtext.add(name,value);
// i want to say get the name and value from outputtext class and draw it in the widget!



}

and the other cpp file (outputtext) as a method add(name, vale) as string:

unsigned int OutPutText::add( std::string name , std::string value )
{
  .....
}

please help!! i think it is easy but I just can't get the painter works from the push-button!

  • Do I understand this correctly: You have a class that is drawing text via paint() method in one class and you want to extract that text to some other class on a PushButton click from a third class? Perhaps you can add some relevant code to your question. – Mateusz Andrzejewski Nov 27 '13 at 13:32
  • Your question is very hard to follow. – drescherjm Nov 27 '13 at 16:00
  • no help? i just wantet to implement the drawing in the pushbutton class but it is not posible..i should be in paintevent! how! – user3041899 Nov 27 '13 at 20:37

1 Answers1

0

problem solved: in order to get the text and drawing in the widget from the on_pushButton_clicked, i had to use QPixmap and QGraphicsscene so that i have a Scene for the Paiter and to show the drawing on the widget i set the size for the Pixmap as so as the size of my widget and make the pixmap transparent...then i have to use QGraphicsviewer to let the scene shows on the widget like the code below!

thanks any way...

void Widget::on_pushButton_clicked()
{


    QPixmap *pixmap = new QPixmap(this->size());
    pixmap->fill(Qt::transparent);
    QGraphicsScene *scene = new QGraphicsScene(this);
    scene->addPixmap(*pixmap);
    QPainter painter(pixmap);

    painter.begin(pixmap);
    painter.drawPixmap(QPoint(0,0), *pixmap);
    painter.drawText(x,y,"my string");

    painter.end();

    QGraphicsView *view = new QGraphicsView(scene, this);
    scene->addPixmap(*pixmap);
    view->setStyleSheet("background: transparent");
    view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    view->show();
}