3 Attachment(s)
QtableView content disapears after associated PrintDialog got cancelled
Hi,
My PrintableTableView class deriving from QTableView is using QWebView to print the content of my model:
Code:
#ifndef PRINTABLETABLEVIEW_H
#define PRINTABLETABLEVIEW_H
// QT includes
#include <QtWebKit>
#include <QtGui>
// non QT includes
Q_OBJECT
public:
PrintableTableView
( QWidget * parent
= 0 );
~PrintableTableView();
public slots:
virtual void print();
void printHtml(bool ok);
protected:
// Webkit things for printing the identifiers
QWebView *m_webview;
};
#endif
Code:
// non QT includes
#include "PrintableTableView.h"
#include "mainWindow.h"
m_webview = new QWebView(this);
m_webview->setVisible(false);
}
PrintableTableView::~PrintableTableView(){
}
void
PrintableTableView::print() {
MainWindow *mainWindow = MainWindow::instance();
// Header
<div id=header>\
<div id=logo>\
<table border=0>\
<tr>\
<th><h1>Empty page</h1></th>\
<th><h2>from %1</h2></th>\
</tr>\
</table>\
<h3>printed on %2</h3>\
</div>\
</div>").
arg(mainWindow
->currentProjectName
()).
arg(QDate::currentDate().
toString());
connect(m_webview, SIGNAL(loadFinished(bool)),this, SLOT(printHtml(bool)));
m_webview->setHtml(m_htmlTemplate, m_baseUrl);
}
void
PrintableTableView::printHtml(bool ok) {
disconnect(m_webview, SIGNAL(loadFinished(bool)),this, SLOT(printHtml(bool)));
if (printDialog.
exec() == QDialog::Accepted) { m_webview->print(&printer);
}
}
PrintableTableView
::readFile(const QString &name
){
qWarning("Unable to open %s: %s", name.toUtf8().constData(), f.errorString().toUtf8().constData());
}
return ts.readAll();
}
The content of the QTableView is displayed correctly before and while I have the printDialog open. Sometimes (yes sometimes, not everytime) it happens that the content of the QTableView disapear if I cancel the printDialog.
What I am doing wrong ?
Re: QtableView content disapears after associated PrintDialog got cancelled
How is the model for the view defined? Also, how do you instantiate your view?
Re: QtableView content disapears after associated PrintDialog got cancelled
Here is how the model for the view is defined and instantiated.
Code:
{
Q_OBJECT
public:
static CommunicationModel
* instance
(QWidget* parent
= 0);
QVariant headerData
(int section, Qt
::Orientation orientation,
int role
= Qt
::DisplayRole) const;
Qt::ItemFlags flags( const QModelIndex& ) const ;
bool addFrame(const Can_Frame &frame);
void clear();
void sort (int column, Qt::SortOrder order = Qt::AscendingOrder );
private:
CommunicationModel
(QObject *parent
= 0);
IdentifiersModel* id_model;
QList<Can_Frame> m_communication; // Communication log
};
Code:
CommunicationView
::CommunicationView( QWidget* parent
) : PrintableTableView(parent)
{
m_model = CommunicationModel::instance(this);
setModel(m_model);
m_delegate = new CommunicationDelegate(this);
setItemDelegate(m_delegate);
.. and how I do instantiate my view ...
Code:
WidgetCommunication
::WidgetCommunication( QWidget* parent
) :{
// Title
title = new TitleFrame(this,"Communication log",true);
// Body
body = CommunicationView::instance(this);
// Status
quickSend = new QuickSend(this);
// Layout
mainLayout->addWidget(title);
mainLayout->addWidget(body);
mainLayout->addWidget(quickSend);
mainLayout->setContentsMargins (0, 0, 0, 0);
setLayout(mainLayout);
}
Re: QtableView content disapears after associated PrintDialog got cancelled
And what's the relation between WidgetCommunication and the print dialog?
Re: QtableView content disapears after associated PrintDialog got cancelled
??..Well PrintDialog is a child of QtableView...
Code:
void
PrintableTableView::printHtml(bool ok) {
disconnect(m_webview, SIGNAL(loadFinished(bool)),this, SLOT(printHtml(bool)));
if (printDialog.
exec() == QDialog::Accepted) { m_webview->print(&printer);
}
}
Re: QtableView content disapears after associated PrintDialog got cancelled
Could you install an event filter on the table and see if it receives a QEvent::Hide?