PDA

View Full Version : Qwt and context menu



giusepped
9th December 2008, 08:59
I am trying to make a context menu, whenever the user right click on my plot.



MyPlot::MyPlot( QWidget* parent) : QwtPlot(parent)

{

this->setContextMenuPolicy(Qt::CustomContextMenu);
connect(this,SIGNAL(customContextMenuRequested(con st QPoint & )),this,SLOT(popUpMenu(const QPoint &)));


and for sure


void MyPlot::popUpMenu(const QPoint &pos)
{
qDebug()<<"meu aperto?"<<pos;
QMenu menu;
menu.addAction(a_print);
menu.popup(pos);
}


But nothing appear.
I forgot something?

giusepped
9th December 2008, 09:55
It seems that if I put


menu.exec(QCursor::pos());


the menu shows up:
But now, I wanna print the qwt plot.
With the following code I can print, but the axis will not be present in the output although it is present in the plot.
Help.


void MyPlot::printOut()
{
QPrinter printer(QPrinter::HighResolution);
printer.setOutputFileName(tr("diagrammasolare.pdf"));
printer.setCreator("Solar Calc");
printer.setOrientation(QPrinter::Landscape);
printer.setOrientation(QPrinter::Portrait);
QPrintDialog dialog(&printer);
if ( dialog.exec() )
{
QwtPlotPrintFilter filter;
if ( printer.colorMode() == QPrinter::GrayScale )
{
int options = QwtPlotPrintFilter::PrintAll;
options &= ~QwtPlotPrintFilter::PrintBackground;
options |= QwtPlotPrintFilter::PrintFrameWithScales;
filter.setOptions(options);
}

print(printer, filter);



}
}