Results 1 to 20 of 20

Thread: How I could Tell Qpainter where is his Area of Painting...

  1. #1
    Join Date
    Nov 2008
    Location
    Caracas - Venezuela
    Posts
    29
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question How I could Tell Qpainter where is his Area of Painting...

    I made a GUI with designer.
    I got a QWidget object called "areadibujo" that has and predetermined area.
    Now the problem is that I dont know how to tell "QPainter" that his Space is That one.

    Which is the way to tell it that?

    Could be QPainterPath? how i could implemented ? I got days within this.
    Am I doing something wrong? any ideas?

    No one?
    Last edited by j0rt4g4; 25th November 2008 at 20:34.

  2. #2
    Join Date
    Nov 2008
    Location
    Caracas - Venezuela
    Posts
    29
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How I could Tell Qpainter where is his Area of Painting...

    Is my question wrong formulated ? :S

  3. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How I could Tell Qpainter where is his Area of Painting...

    What it is you want to do?
    ANY widget that you can see is painted by QPainter.
    If you want to change the way a particular widget is being drawn, you should overload the paintEvent() of that widget.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  4. #4
    Join Date
    Nov 2008
    Location
    Caracas - Venezuela
    Posts
    29
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How I could Tell Qpainter where is his Area of Painting...

    I got a image like this:

    In the Center of this image there's a widget called "areadibujo",
    I want to paint ON this area, but I dont know how to do it.

    I want to create a code that read a file data
    (%f %f ) insert it on a array
    a[i] b[i]

    And use the array to do some math, and get the points on areadibujo but I guess I'm confused with parents.

    Well here's my code:
    main.cpp:
    Qt Code:
    1. #include <QApplication>
    2. #include "fractal.h"
    3. #include "renderarea.h"
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. QApplication app(argc, argv);
    8. fractal *dialog = new fractal;
    9. //renderarea *dialog= new renderarea;
    10.  
    11. dialog->show();
    12. return app.exec();
    13. }
    To copy to clipboard, switch view to plain text mode 

    fractal.h
    Qt Code:
    1. #ifndef __FRACTAL_H__
    2. #define __FRACTAL_H__
    3. #include "ui_fractals.h"
    4.  
    5.  
    6. class fractal : public QWidget, private Ui::Fractals
    7. {
    8. Q_OBJECT
    9.  
    10. public:
    11. fractal(QWidget *parent = 0);
    12. void updateBrush();
    13.  
    14. public slots:
    15. void setOpenFileName();
    16. void QPaintEvent(QPainter *event);
    17. };
    18.  
    19.  
    20. #endif // __FRACTAL_H__
    To copy to clipboard, switch view to plain text mode 

    fractal.cpp
    Qt Code:
    1. #include <QtGui>
    2. #include <QFile>
    3. #include <QGLWidget>
    4. #include <QtOpenGL>
    5. #include "fractal.h"
    6.  
    7. void tidyFile(QIODevice *inDevice, QIODevice *outDevice)
    8. {
    9. QTextStream in(inDevice);
    10. QTextStream out(outDevice);
    11.  
    12. int endlCount = 0;
    13. QChar ch;
    14.  
    15. while (!in.atEnd()) {
    16. in >> ch;
    17.  
    18. if (ch == '\n') {
    19. ++endlCount;
    20. }
    21. }
    22. // out << endl;
    23. }
    24.  
    25.  
    26. fractal::fractal(QWidget *parent){
    27. setupUi(this);
    28. connect( toolButton, SIGNAL( clicked() ), this, SLOT( setOpenFileName() ) );
    29. connect( boton_aceptar, SIGNAL( clicked() ), this, SLOT( QPaintEvent(QPainter *event) ) );
    30. }
    31.  
    32.  
    33. void fractal::setOpenFileName()
    34. {
    35. QFileDialog::Options options;
    36. options |=QFileDialog::ShowDirsOnly;
    37.  
    38.  
    39. QString selectedFilter;
    40. QString fileName = QFileDialog::getOpenFileName(this,
    41. tr("QFileDialog::getOpenFileName()"),
    42. lineEdit->text(),
    43. tr("Todos (*);;Data (*.txt)"),
    44. &selectedFilter,
    45. options);
    46. if (!fileName.isEmpty())
    47. lineEdit->setText(fileName);
    48.  
    49. QFile infile;
    50. QFile outfile;
    51. infile.open(stdin, QFile::ReadOnly);
    52. outfile.open(stdout, QFile::WriteOnly);
    53. tidyFile(&infile,&outfile);
    54. QTextStream in(&infile);
    55. QTextStream out(&outfile);
    56. int endlCount = 0;
    57. QChar ch;
    58. while (!in.atEnd()) {
    59. in >> ch;
    60. if (ch == '\n') {
    61. ++endlCount;
    62. }
    63. }
    64. }
    65.  
    66. void fractal::QPaintEvent(QPainter *event){
    67. QPainter painter(this);
    68. painter.setRenderHint(QPainter::Antialiasing, true);
    69. painter.setPen(QPen(Qt::black, 15, Qt::SolidLine, Qt::RoundCap,
    70. Qt::MiterJoin));
    71. painter.setBrush(QBrush(Qt::blue, Qt::DiagCrossPattern));
    72. painter.drawPie(80, 80, 400, 240, 60 * 16, 270 * 16);
    73. }
    To copy to clipboard, switch view to plain text mode 
    I hope I wasn't wasting my time as I hope...
    Last edited by j0rt4g4; 26th November 2008 at 16:34.

  5. #5
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How I could Tell Qpainter where is his Area of Painting...

    it is wrong
    Qt Code:
    1. void fractal::QPaintEvent(QPainter *event)
    To copy to clipboard, switch view to plain text mode 
    must be
    Qt Code:
    1. void fractal::paintEvent(QPaintEvent *event) {
    2. //draw something
    3. }
    To copy to clipboard, switch view to plain text mode 

    and then you must draw what you want
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  6. #6
    Join Date
    Nov 2008
    Location
    Caracas - Venezuela
    Posts
    29
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How I could Tell Qpainter where is his Area of Painting...

    Ok I made Corrections and IT DRAWS (thank you very much)... But It is painting on the BIG Widget (mainwindow) and It is not ON the widget called (areadibujo).

    If you want to change the way a particular widget is being drawn, you should overload the paintEvent() of that widget
    Could you tell me how I do that in here ?
    Thank you very much

  7. #7
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How I could Tell Qpainter where is his Area of Painting...

    is this "areadibujo" independent? if yes then you have to override paintEvent of this widget.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  8. #8
    Join Date
    Nov 2008
    Location
    Caracas - Venezuela
    Posts
    29
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How I could Tell Qpainter where is his Area of Painting...

    mmm I guess it is a son of "Fractals"


    Isnt it easier make it independient?, T.T because I dont know how to do it independient eighter... (:S what a noobie guy).... I'm trying .
    Last edited by j0rt4g4; 26th November 2008 at 17:08.

  9. #9
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How I could Tell Qpainter where is his Area of Painting...

    yep. so you can do next: install event filter for this widget and handle paint event and draw what you need, e.g.
    Qt Code:
    1. Test::Test(QWidget *parent)
    2. : QMainWindow(parent)
    3. {
    4. QVBoxLayout *vbl = new QVBoxLayout();
    5. QWidget *w = new QWidget;
    6. m_drawer = new QWidget();
    7. m_drawer->installEventFilter(this);//set event filter
    8.  
    9. vbl->addWidget(m_drawer);
    10. vbl->addWidget(new QWidget);
    11. w->setLayout(vbl);
    12.  
    13. setCentralWidget(w);
    14. }
    15.  
    16. bool Test::eventFilter(QObject *o, QEvent *e)
    17. {
    18. if (o == m_drawer && e->type() == QEvent::Paint) {//process paint event of needed widget
    19. QPainter painter(m_drawer);
    20. painter.setPen(Qt::blue);
    21. painter.setFont(QFont("Arial", 30));
    22. painter.drawText(m_drawer->rect(), Qt::AlignCenter, "Qt");
    23. return true;
    24. }
    25. return QMainWindow::eventFilter(o, e);
    26. }
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  10. The following 2 users say thank you to spirit for this useful post:

    j0rt4g4 (26th November 2008), tpf80 (22nd January 2009)

  11. #10
    Join Date
    Nov 2008
    Location
    Caracas - Venezuela
    Posts
    29
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How I could Tell Qpainter where is his Area of Painting...

    Like this?

    ui_Fractals.h:
    Qt Code:
    1. QT_BEGIN_NAMESPACE
    2.  
    3. class Ui_Fractals
    4. {
    5. public:
    6. QWidget *layoutWidget;
    7. QHBoxLayout *horizontalLayout_4;
    8. QVBoxLayout *verticalLayout_2;
    9. QHBoxLayout *horizontalLayout_3;
    10. QLabel *label_Archivo;
    11. QLineEdit *lineEdit;
    12. QToolButton *toolButton;
    13. QWidget *areadibujo;
    14. QVBoxLayout *verticalLayout;
    15. QHBoxLayout *horizontalLayout;
    16. QLabel *Iterations;
    17. QSpinBox *spinbox_ite;
    18. QSlider *iterator_hslider;
    19. QSpacerItem *verticalSpacer;
    20. QHBoxLayout *horizontalLayout_2;
    21. QPushButton *boton_aceptar;
    22. QPushButton *boton_salir;
    23.  
    24. void setupUi(QWidget *Fractals)
    25. {
    26. if (Fractals->objectName().isEmpty())
    27. Fractals->setObjectName(QString::fromUtf8("Fractals"));
    28. Fractals->resize(605, 408);
    29. layoutWidget = new QWidget(Fractals);
    30. layoutWidget->setObjectName(QString::fromUtf8("layoutWidget"));
    31. layoutWidget->setGeometry(QRect(10, 10, 579, 382));
    32. horizontalLayout_4 = new QHBoxLayout(layoutWidget);
    33. horizontalLayout_4->setObjectName(QString::fromUtf8("horizontalLayout_4"));
    34. horizontalLayout_4->setContentsMargins(0, 0, 0, 0);
    35. verticalLayout_2 = new QVBoxLayout();
    36. verticalLayout_2->setObjectName(QString::fromUtf8("verticalLayout_2"));
    37. horizontalLayout_3 = new QHBoxLayout();
    38. horizontalLayout_3->setObjectName(QString::fromUtf8("horizontalLayout_3"));
    39. label_Archivo = new QLabel(layoutWidget);
    40. label_Archivo->setObjectName(QString::fromUtf8("label_Archivo"));
    41.  
    42. horizontalLayout_3->addWidget(label_Archivo);
    43.  
    44. lineEdit = new QLineEdit(layoutWidget);
    45. lineEdit->setObjectName(QString::fromUtf8("lineEdit"));
    46. lineEdit->setEnabled(false);
    47. lineEdit->setMinimumSize(QSize(280, 0));
    48. lineEdit->setDragEnabled(false);
    49.  
    50. horizontalLayout_3->addWidget(lineEdit);
    51.  
    52. toolButton = new QToolButton(layoutWidget);
    53. toolButton->setObjectName(QString::fromUtf8("toolButton"));
    54. toolButton->setMinimumSize(QSize(25, 20));
    55. toolButton->setCheckable(false);
    56. toolButton->setPopupMode(QToolButton::DelayedPopup);
    57. toolButton->setArrowType(Qt::NoArrow);
    58.  
    59. horizontalLayout_3->addWidget(toolButton);
    60.  
    61.  
    62. verticalLayout_2->addLayout(horizontalLayout_3);
    63.  
    64. areadibujo = new QWidget(layoutWidget);
    65. areadibujo->setObjectName(QString::fromUtf8("areadibujo"));
    66. areadibujo->setMinimumSize(QSize(350, 350));
    67. areadibujo->setMaximumSize(QSize(500, 500));
    68. areadibujo->setAutoFillBackground(false);
    69. areadibujo->installEventFilter(this); ////////////////////////////here!:confused::confused:
    70.  
    71.  
    72. verticalLayout_2->addWidget(areadibujo);
    73.  
    74.  
    75. horizontalLayout_4->addLayout(verticalLayout_2);
    76.  
    77. verticalLayout = new QVBoxLayout();
    78. verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
    79. horizontalLayout = new QHBoxLayout();
    80. horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
    81. Iterations = new QLabel(layoutWidget);
    82. Iterations->setObjectName(QString::fromUtf8("Iterations"));
    83.  
    84. horizontalLayout->addWidget(Iterations);
    85.  
    86. spinbox_ite = new QSpinBox(layoutWidget);
    87. spinbox_ite->setObjectName(QString::fromUtf8("spinbox_ite"));
    88. spinbox_ite->setEnabled(true);
    89. spinbox_ite->setMinimumSize(QSize(30, 0));
    90. spinbox_ite->setMinimum(100000);
    91. spinbox_ite->setMaximum(1000000);
    92. spinbox_ite->setSingleStep(1000);
    93. spinbox_ite->setValue(100000);
    94.  
    95. horizontalLayout->addWidget(spinbox_ite);
    96.  
    97. iterator_hslider = new QSlider(layoutWidget);
    98. iterator_hslider->setObjectName(QString::fromUtf8("iterator_hslider"));
    99. iterator_hslider->setEnabled(true);
    100. iterator_hslider->setMouseTracking(true);
    101. iterator_hslider->setMinimum(100000);
    102. iterator_hslider->setMaximum(1000000);
    103. iterator_hslider->setSingleStep(1000);
    104. iterator_hslider->setPageStep(100000);
    105. iterator_hslider->setValue(100000);
    106. iterator_hslider->setTracking(true);
    107. iterator_hslider->setOrientation(Qt::Horizontal);
    108.  
    109. horizontalLayout->addWidget(iterator_hslider);
    110.  
    111.  
    112. verticalLayout->addLayout(horizontalLayout);
    113.  
    114. verticalSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
    115.  
    116. verticalLayout->addItem(verticalSpacer);
    117.  
    118. horizontalLayout_2 = new QHBoxLayout();
    119. horizontalLayout_2->setObjectName(QString::fromUtf8("horizontalLayout_2"));
    120. boton_aceptar = new QPushButton(layoutWidget);
    121. boton_aceptar->setObjectName(QString::fromUtf8("boton_aceptar"));
    122.  
    123. horizontalLayout_2->addWidget(boton_aceptar);
    124.  
    125. boton_salir = new QPushButton(layoutWidget);
    126. boton_salir->setObjectName(QString::fromUtf8("boton_salir"));
    127.  
    128. horizontalLayout_2->addWidget(boton_salir);
    129.  
    130.  
    131. verticalLayout->addLayout(horizontalLayout_2);
    132.  
    133.  
    134. horizontalLayout_4->addLayout(verticalLayout);
    135.  
    136.  
    137. retranslateUi(Fractals);
    138. QObject::connect(boton_salir, SIGNAL(clicked()), Fractals, SLOT(close()));
    139. QObject::connect(spinbox_ite, SIGNAL(valueChanged(int)), iterator_hslider, SLOT(setValue(int)));
    140. QObject::connect(iterator_hslider, SIGNAL(valueChanged(int)), spinbox_ite, SLOT(setValue(int)));
    141.  
    142. QMetaObject::connectSlotsByName(Fractals);
    143. } // setupUi
    144.  
    145. void retranslateUi(QWidget *Fractals)
    146. {
    147. Fractals->setWindowTitle(QApplication::translate("Fractals", "Fractals", 0, QApplication::UnicodeUTF8));
    148. label_Archivo->setText(QApplication::translate("Fractals", "Archivo:", 0, QApplication::UnicodeUTF8));
    149. toolButton->setText(QApplication::translate("Fractals", "...", 0, QApplication::UnicodeUTF8));
    150. Iterations->setText(QApplication::translate("Fractals", "Iterations", 0, QApplication::UnicodeUTF8));
    151. boton_aceptar->setText(QApplication::translate("Fractals", "&Aceptar", 0, QApplication::UnicodeUTF8));
    152. boton_salir->setText(QApplication::translate("Fractals", "&Salir", 0, QApplication::UnicodeUTF8));
    153. Q_UNUSED(Fractals);
    154. } // retranslateUi
    155.  
    156. };
    157.  
    158. namespace Ui {
    159. class Fractals: public Ui_Fractals {};
    160. } // namespace Ui
    161.  
    162. QT_END_NAMESPACE
    163.  
    164.  
    165. bool areadibujo::eventFilter(QObject *o, QEvent *e) //////////and here:confused::confused:
    166. {
    167. if(o == areadibujo && e->type() == QEvent::Paint){
    168. QPainter painter(areadibujo);
    169. painter.setPen(Qt::blue);
    170. painter.setFont(QFont("Arial",30));
    171. painter.drawText(areadibujo->rect(), Qt::AlignCenter,"Probando");
    172. return true;
    173. }
    174. return Ui_Fractals::eventFilter(o,e);
    175. }
    176.  
    177. #endif // UI_FRACTALS_H
    To copy to clipboard, switch view to plain text mode 

  12. #11
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How I could Tell Qpainter where is his Area of Painting...

    no, not in generated h-file. you should install filter in that widget for which you set up ui, i.e.
    Qt Code:
    1. fractal::fractal(QWidget *parent)
    2. : QWidget(parent)
    3. {
    4. setupUi(this);
    5. areadibujo->installEventFilter(this);
    6. connect( toolButton, SIGNAL( clicked() ), this, SLOT( setOpenFileName() ) );
    7. }
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  13. #12
    Join Date
    Nov 2008
    Location
    Caracas - Venezuela
    Posts
    29
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How I could Tell Qpainter where is his Area of Painting...

    Welll...... It runs but doesn't show anything...
    I did it like this :

    main.cpp
    Qt Code:
    1. #include <QApplication>
    2. #include "fractal.h"
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication app(argc, argv);
    7. fractal *dialog = new fractal;
    8. //renderarea *dialog= new renderarea;
    9.  
    10. dialog->show();
    11. return app.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 

    fractal.h:
    Qt Code:
    1. #ifndef __FRACTAL_H__
    2. #define __FRACTAL_H__
    3. #include "ui_fractals.h"
    4.  
    5.  
    6. class fractal : public QWidget, private Ui::Fractals
    7. {
    8. Q_OBJECT
    9.  
    10. public:
    11. fractal(QWidget *parent = 0);
    12. void updateBrush();
    13. // bool eventFilter(QObject *o, QEvent *e);
    14. public slots:
    15. void setOpenFileName();
    16. void paintEvent(QPaintEvent *event);
    17. bool eventFilter(QObject *o, QEvent *e);
    18. };
    19.  
    20.  
    21. #endif // __FRACTAL_H__
    To copy to clipboard, switch view to plain text mode 

    fractal.cpp:
    Qt Code:
    1. #include <QFile>
    2. #include <QGLWidget>
    3. #include <QtOpenGL>
    4. #include "fractal.h"
    5.  
    6. void tidyFile(QIODevice *inDevice, QIODevice *outDevice)
    7. {
    8. QTextStream in(inDevice);
    9. QTextStream out(outDevice);
    10.  
    11. int endlCount = 0;
    12. QChar ch;
    13.  
    14. while (!in.atEnd()) {
    15. in >> ch;
    16.  
    17. if (ch == '\n') {
    18. ++endlCount;
    19. }
    20. }
    21. // out << endl;
    22. }
    23.  
    24.  
    25. fractal::fractal(QWidget *parent){
    26. setupUi(this);
    27. areadibujo->installEventFilter(this);
    28. connect( toolButton, SIGNAL( clicked() ), this, SLOT( setOpenFileName() ) );
    29. connect( boton_aceptar, SIGNAL( clicked() ), this, SLOT( QPaintEvent(QPainter *event) ) );
    30. }
    31.  
    32.  
    33. void fractal::setOpenFileName()
    34. {
    35. QFileDialog::Options options;
    36. options |=QFileDialog::ShowDirsOnly;
    37.  
    38.  
    39. QString selectedFilter;
    40. QString fileName = QFileDialog::getOpenFileName(this,
    41. tr("QFileDialog::getOpenFileName()"),
    42. lineEdit->text(),
    43. tr("Todos (*);;Data (*.txt)"),
    44. &selectedFilter,
    45. options);
    46. if (!fileName.isEmpty())
    47. lineEdit->setText(fileName);
    48.  
    49. QFile infile;
    50. QFile outfile;
    51. infile.open(stdin, QFile::ReadOnly);
    52. outfile.open(stdout, QFile::WriteOnly);
    53. tidyFile(&infile,&outfile);
    54. QTextStream in(&infile);
    55. QTextStream out(&outfile);
    56. int endlCount = 0;
    57. QChar ch;
    58. while (!in.atEnd()) {
    59. in >> ch;
    60. if (ch == '\n') {
    61. ++endlCount;
    62. }
    63. }
    64. }
    65.  
    66. void fractal::paintEvent(QPaintEvent *event){
    67. QPainter painter(this);
    68. painter.setRenderHint(QPainter::Antialiasing, true);
    69. painter.setPen(QPen(Qt::black, 15, Qt::SolidLine, Qt::RoundCap,
    70. Qt::MiterJoin));
    71. painter.setBrush(QBrush(Qt::blue, Qt::DiagCrossPattern));
    72. painter.setPen(QPen(Qt::red, 5, Qt::SolidLine, Qt::RoundCap,Qt::MiterJoin));
    73.  
    74. painter.translate(100.0,100.0);
    75. painter.drawPie(0, 0, 300, 300, 60 * 16, 270 * 16);
    76. painter.drawEllipse(30,30,60,60);
    77.  
    78. }
    79.  
    80. bool fractal::eventFilter(QObject *o, QEvent *e)
    81. {
    82. if (o == areadibujo && e->type() == QEvent::Paint) {//process paint event of needed widget
    83. QPainter painter(areadibujo);
    84. painter.setPen(Qt::blue);
    85. painter.setFont(QFont("Arial", 30));
    86. painter.drawText(areadibujo->rect(), Qt::AlignCenter, "Qt");
    87. return true;
    88. }
    89. return fractal::eventFilter(o, e);
    90. }
    To copy to clipboard, switch view to plain text mode 

  14. #13
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How I could Tell Qpainter where is his Area of Painting...

    comment fractal:aintEvent and replace this snippet return fractal::eventFilter(o, e); with QWidget::eventFilter(o ,e);
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

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

    Default Re: How I could Tell Qpainter where is his Area of Painting...

    Maybe it would be advised to at least take a brief look at the documentation of methods you are using?

  16. #15
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How I could Tell Qpainter where is his Area of Painting...

    look at this example in the attach, it should help you.
    Attached Files Attached Files
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  17. The following user says thank you to spirit for this useful post:

    j0rt4g4 (26th November 2008)

  18. #16
    Join Date
    Nov 2008
    Location
    Caracas - Venezuela
    Posts
    29
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How I could Tell Qpainter where is his Area of Painting...

    Ok I did that:
    return fractal::eventFilter(o, e); with return QWidget::eventFilter(o ,e);

    Finally solved.
    Now how I can print what a QTextStream is reading in stdout?
    (in the console)
    Because I'm not sure that is opening and reading the file the way must be.
    There are the first 2 implementation on the fractal.cpp.
    Im trying to read a text file, with this format in C#
    "0.065\t0.555\t0.5\n"

    I tried counting lines first to know the number of items in array (I know this is not necessary in Qt because I should have used "array.append()" ) and make the QString a Qdouble making a "cast"...

    I have been a week trying to do this for myself, and I got lot's and lot's of doubts.... I apologyze for asking that much... But If I knew I wouldn't ask...

  19. #17
    Join Date
    Nov 2008
    Location
    Caracas - Venezuela
    Posts
    29
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How I could Tell Qpainter where is his Area of Painting...

    Quote Originally Posted by wysota View Post
    Maybe it would be advised to at least take a brief look at the documentation of methods you are using?
    I did that and I got all classes of QT what I'm ussing printed. But I was trying to go out of all my doubts YELLING FOR HELP...
    I have many of examples printed but I dont want to bother but I want to learn... So I ask.
    I'm sorry...

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

    Default Re: How I could Tell Qpainter where is his Area of Painting...

    So don't print ALL, read the ones you need. If you have too much reference, you'll get lost in it. Focus on one task at a time.

  21. #19
    Join Date
    Nov 2008
    Location
    Caracas - Venezuela
    Posts
    29
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default

    Quote Originally Posted by spirit View Post
    look at this example in the attach, it should help you.
    I look this example ... The event was a protected type of fractal ...
    Thanks you very much for helping me.

    I had that doubt for long time ago. But I'm sure it must be a easier way to do the things, but I'm doing the best of I can with my knowledge. I don't wanna be this noob anymore :P

    Quote Originally Posted by wysota View Post
    So don't print ALL, read the ones you need. If you have too much reference, you'll get lost in it. Focus on one task at a time.
    I printed the ones I think I would use for this. And I read them too. But the way is mading by walking through it . Finally, I want to thank you for your advise I would keep it in mind.

    Sometimes reference is old (Qt3) and must be "correctly traslade" for working on Qt4, I have like 1 moths reading about this (Qt4.4.1 & Qt4.4.3, and I'm moving from C# languague to C++, I will learn, but be pacient), sometimes I got confused but testing is the way to get out of doubts.
    Last edited by wysota; 26th November 2008 at 19:54.

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

    Default Re: How I could Tell Qpainter where is his Area of Painting...

    All reference you may need is in your Qt Assistant. Just launch the application and enjoy. No need to browse any Qt3 docs.

Similar Threads

  1. Replies: 7
    Last Post: 20th March 2006, 20:03
  2. 2 Questions about QPainter
    By SkripT in forum Qt Programming
    Replies: 12
    Last Post: 22nd February 2006, 15:08
  3. Trouble with image painting (QPainter + QImage)
    By krivenok in forum Qt Programming
    Replies: 1
    Last Post: 4th February 2006, 20:25
  4. QRubberBand painting in the scroll area widget
    By SkripT in forum Qt Programming
    Replies: 7
    Last Post: 17th January 2006, 16:48

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.