Results 1 to 2 of 2

Thread: Promote to ..

  1. #1
    Join Date
    Feb 2011
    Posts
    22
    Qt products
    Qt3 Qt4
    Platforms
    Windows
    Thanks
    1

    Default Promote to ..

    Hallo all,

    I manage to adapt the tvplot example in my app. It works ok and i can see the plot. My issue now is to see the plot included in an already implemented dialog box. I read this has to be done via promote widget but when i promote to my Plot class i get many errors. Please i need urgently some help .

    Find below the code of the cpp and h file of the plot

    cpp
    Qt Code:
    1. #include <stdlib.h>
    2. #include <qpen.h>
    3. #include <qwt_plot_layout.h>
    4. #include <qwt_legend.h>
    5. #include <qwt_legend_item.h>
    6. #include <qwt_plot_grid.h>
    7. #include <qwt_plot_histogram.h>
    8. #include <qwt_column_symbol.h>
    9. #include <qwt_series_data.h>
    10. #include "plot.h"
    11.  
    12. class Histogram: public QwtPlotHistogram
    13. {
    14. public:
    15. Histogram(const QString &, const QColor &);
    16.  
    17. void setColor(const QColor &);
    18. void setValues(uint numValues, char *);
    19. };
    20.  
    21. Histogram::Histogram(const QString &title, const QColor &symbolColor):
    22. QwtPlotHistogram(title)
    23. {
    24. setStyle(QwtPlotHistogram::Columns);
    25.  
    26. setColor(symbolColor);
    27. }
    28.  
    29. void Histogram::setColor(const QColor &symbolColor)
    30. {
    31. QColor color = symbolColor;
    32. color.setAlpha(180);
    33.  
    34. setPen(QPen(Qt::black));
    35. setBrush(QBrush(color));
    36.  
    37. QwtColumnSymbol *symbol = new QwtColumnSymbol(QwtColumnSymbol::Box);
    38. symbol->setFrameStyle(QwtColumnSymbol::Raised);
    39. symbol->setLineWidth(2);
    40. symbol->setPalette(QPalette(color));
    41. setSymbol(symbol);
    42. }
    43.  
    44. void Histogram::setValues(uint numValues, char *values)
    45. {
    46. QVector<QwtIntervalSample> samples(numValues);
    47. for ( uint i = 0; i < numValues; i++ )
    48. {
    49. QwtInterval interval(double(i), i + 1.0);
    50. interval.setBorderFlags(QwtInterval::ExcludeMaximum);
    51.  
    52. samples[i] = QwtIntervalSample(values[i], interval);
    53. }
    54.  
    55. setData(new QwtIntervalSeriesData(samples));
    56. }
    57.  
    58. Plot::Plot(QWidget *parent):
    59. QwtPlot(parent)
    60. {
    61. setTitle("Patient Adherence");
    62.  
    63. setCanvasBackground(QColor(Qt::gray));
    64. plotLayout()->setAlignCanvasToScales(true);
    65.  
    66. setAxisTitle(QwtPlot::yLeft, "Probability(%)");
    67. setAxisTitle(QwtPlot::xBottom, "Adherence");
    68.  
    69. QwtLegend *legend = new QwtLegend;
    70. legend->setItemMode(QwtLegend::CheckableItem);
    71. insertLegend(legend, QwtPlot::RightLegend);
    72.  
    73. populate();
    74.  
    75. // connect(this, SIGNAL(legendChecked(QwtPlotItem *, bool)),
    76. // SLOT(showItem(QwtPlotItem *, bool)));
    77.  
    78. replot(); // creating the legend items
    79.  
    80. QwtPlotItemList items = itemList(QwtPlotItem::Rtti_PlotHistogram);
    81. for ( int i = 0; i < items.size(); i++ )
    82. {
    83. if ( i == 0 )
    84. {
    85. QwtLegendItem *legendItem = (QwtLegendItem *)legend->find(items[i]);
    86. if ( legendItem )
    87. legendItem->setChecked(true);
    88. items[i]->setVisible(true);
    89. }
    90. else
    91. items[i]->setVisible(false);
    92. }
    93.  
    94. setAutoReplot(true);
    95. }
    96.  
    97. void Plot::populate()
    98. {
    99. QwtPlotGrid *grid = new QwtPlotGrid;
    100. grid->enableX(false);
    101. grid->enableY(true);
    102. grid->enableXMin(false);
    103. grid->enableYMin(false);
    104. grid->setMajPen(QPen(Qt::black, 0, Qt::DotLine));
    105. grid->attach(this);
    106.  
    107. char patientValues[] = { 'a', 'd', 'na'};
    108.  
    109.  
    110. Histogram *histogramClient = new Histogram("Blue Pills", Qt::red);
    111. histogramClient->setValues(
    112. sizeof(clientValues) / sizeof(char), clientValues);
    113. histogramClient->attach(this);
    114.  
    115. }
    116.  
    117. void Plot::showItem(QwtPlotItem *item, bool on)
    118. {
    119. item->setVisible(on);
    120. }
    To copy to clipboard, switch view to plain text mode 

    .h
    Qt Code:
    1. #pragma once
    2.  
    3. #include <qwt_plot.h>
    4.  
    5. class Plot: public QObject, public QwtPlot
    6. {
    7. Q_OBJECT
    8.  
    9. public:
    10. Plot(QWidget * = NULL);
    11.  
    12. private:
    13. void populate();
    14.  
    15. private Q_SLOTS:
    16. void showItem(QwtPlotItem *, bool on);
    17. };
    To copy to clipboard, switch view to plain text mode 

    Thank you in advance!

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,326
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 880 Times in 828 Posts

    Default Re: Promote to ..

    Quote Originally Posted by fantom View Post
    I read this has to be done via promote widget but when i promote to my Plot class i get many errors.
    Do you really expect to get an answer without any further information about the errors ?

    Uwe

Similar Threads

  1. code for promote to
    By andreime in forum Qt Programming
    Replies: 2
    Last Post: 15th July 2009, 16:18
  2. how to promote layout in Designer?
    By homerli in forum Qt Tools
    Replies: 1
    Last Post: 11th May 2009, 17:40
  3. QFormBuilder+Designer's Promote to ...
    By OriginalCopy in forum Qt Programming
    Replies: 2
    Last Post: 8th November 2007, 17:43
  4. promote to...
    By uygar in forum Qt Programming
    Replies: 1
    Last Post: 11th October 2007, 10:07
  5. How Could I promote Qt's Drawing performance?
    By joeshow in forum Qt Programming
    Replies: 5
    Last Post: 11th September 2007, 19:04

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.