Hello,
I'm using a custom Qt plugin with and API another team gave me. My understanding problem is about data binding and UI refresh.
The small plugin I use gets instantiated when I open the main GUI, then if I click on a menu item it gets enabled (visible).
My QListView doesn't show, I see an empty rounded frame with a border so there is some empty widget.
So here is some code to check what are coding guidelines I miss...
Thank you very much.
// constructor that gets called when opening up main GUI
AppletTutorial2Imp
::AppletTutorial2Imp(QObject *parent
) : XApplet
(parent
) { m_enabled = false;
// Set up main widget
m_mainWidget->layout()->addWidget(m_listview);
// Assign main widget for applet to display
setWidget(m_mainWidget);
}
// constructor that gets called when opening up main GUI
AppletTutorial2Imp::AppletTutorial2Imp(QObject *parent) : XApplet(parent) {
m_enabled = false;
// Set up main widget
m_mainWidget = new QWidget();
m_mainWidget->setLayout(new QHBoxLayout());
m_listview = new QListView();
m_mainWidget->layout()->addWidget(m_listview);
// Assign main widget for applet to display
setWidget(m_mainWidget);
}
To copy to clipboard, switch view to plain text mode
// code that gets called when choosing a menu item to display a specific module (plugin)
void AppletTutorial2Imp::setEnable(bool enable) {
if(m_enabled != enable) {
m_enabled = enable;
}
if(m_enabled) {
listDicomImages();
}
}
// code that gets called when choosing a menu item to display a specific module (plugin)
void AppletTutorial2Imp::setEnable(bool enable) {
if(m_enabled != enable) {
m_enabled = enable;
}
if(m_enabled) {
listDicomImages();
}
}
To copy to clipboard, switch view to plain text mode
// Code that feeds QListView model and assign model to QListView
void AppletTutorial2Imp::listDicomImages() {
DicomImageModel model;
foreach... {
// Get object from memory query then:
model.addImage(image);
}
m_listview->setModel(&model);
}
// Code that feeds QListView model and assign model to QListView
void AppletTutorial2Imp::listDicomImages() {
DicomImageModel model;
foreach... {
// Get object from memory query then:
model.addImage(image);
}
m_listview->setModel(&model);
}
To copy to clipboard, switch view to plain text mode
Added after 15 minutes:
OK it seems to behave better if in my model class I have data retrieval that works. When I get an exception accessing non existing data it gets trapped. So I have more logs (I removed log statements from code pasted here) but still blank list view.
In my model I implemented only the following:
// constructor, destructor, then:
int DicomImageModel
::rowCount(const QModelIndex & /*parent*/) const {
return m_dicomImages.size();
}
int DicomImageModel
::columnCount(const QModelIndex & /*parent*/) const {
return 6;
}
{
int row = index.row();
int col = index.column();
if(role == Qt::DisplayRole){
if (col
== 0) return QString(m_dicomImages
[row
]->getId
());
if (col
== 1) return QString(m_dicomImages
[row
]->getDicomRef
().
getSeriesInstanceUID());
.arg(row + 1)
.arg(col +1);
}
}
void DicomImageModel::addImage(const XImageObjectPtr image)
{
m_dicomImages.push_back(image);
}
// constructor, destructor, then:
int DicomImageModel::rowCount(const QModelIndex & /*parent*/) const
{
return m_dicomImages.size();
}
int DicomImageModel::columnCount(const QModelIndex & /*parent*/) const
{
return 6;
}
QVariant DicomImageModel::data(const QModelIndex &index, int role) const
{
int row = index.row();
int col = index.column();
if(role == Qt::DisplayRole){
if (col == 0) return QString(m_dicomImages[row]->getId());
if (col == 1) return QString(m_dicomImages[row]->getDicomRef().getSeriesInstanceUID());
return QString("Row%1, Column%2")
.arg(row + 1)
.arg(col +1);
}
return QVariant();
}
void DicomImageModel::addImage(const XImageObjectPtr image)
{
m_dicomImages.push_back(image);
}
To copy to clipboard, switch view to plain text mode
I changed the add item handling method in the model but list remains empty... so where is it wrong??
void DicomImageModel::addImage(const XImageObjectPtr image)
{
beginInsertRows
(QModelIndex(), m_dicomImages.
size(), m_dicomImages.
size());
m_dicomImages.push_back(image);
endInsertRows();
}
void DicomImageModel::addImage(const XImageObjectPtr image)
{
beginInsertRows(QModelIndex(), m_dicomImages.size(), m_dicomImages.size());
m_dicomImages.push_back(image);
endInsertRows();
}
To copy to clipboard, switch view to plain text mode
Bookmarks