PDA

View Full Version : How to disable individual members of a QHash and QList?



in_dbasu
21st July 2011, 06:35
In my project i have a widget which have a QHash vector table and QList on it.I want to access each individual members of the QHash and QList and then disable the members.But i don't get any function to disable the members.

Code:


for(index=0;index<screen.children.count;index++)
{

screen.children.at(index).?

}

Here screen is a QWidget. In Qwidget class we have a function called setdisabled which can be used to disable the whole widget but how to disable the individual members?

ChrisW67
21st July 2011, 07:20
It makes no sense to talk about "disable the members". If you don't want something in the container then either don't add it or QList::removeAt()/QHash::remove() it. QHash and QList are containers that can contain almost anything and have no visible presence, i.e. they cannot be "on" a QWidget.

Your code snippet also makes little sense. QObject::children() returns a list of QObject pointers, only some of these (if any) will be QWidgets that have any sort of visible presence. To access these as QWidgets through this path you will have to qobject_cast<QWidget*>() and check if the result is not null.

It really is easier to keep a pointer to the widgets you wish to disable than to try to find them indirectly later.

in_dbasu
21st July 2011, 07:59
Ok Chris here is the code snippet.....


QAppScreen::QAppScreen(QWidget *parent) : QWidget(parent) {
#ifdef QT_DEBUG_APPLICATION_SCREEN
qDebug() << "QTmApplicationScreen:" << "Create Application Screen";
#endif
setLayout(new QVBoxLayout);
//setLayout(new QHBoxLayout);//Added
m_deviceList = new QHash<int, QWidget *>();
m_iconList = new QList<QAppIcon *>();
}


void QAppScreen::addApplication(QTmApplication *application,QWidget *mwidget) {
#ifdef QT_DEBUG_APPLICATION_SCREEN
qDebug() << "QTmApplicationScreen:" << "Add Application" << application->name() << "to App List" << application->upnpControlPointId();
#endif
if (!m_deviceList->contains(application->upnpControlPointId())) {
QWidget *widget = new QWidget(this);
widget->setLayout(new QHBoxLayout);
layout()->addWidget(widget);
//layout()->addWidget(mwidget);
m_deviceList->insert(application->upnpControlPointId(), widget);

}
QAppIcon *icon = new QAppIcon(application, this);
m_deviceList->value(application->upnpControlPointId())->layout()->addWidget(icon);
m_deviceList->value(application->upnpControlPointId())->layout()->addWidget(mwidget);

connect(icon, SIGNAL(clicked(QTmApplication*)), this, SIGNAL(launchApplication(QTmApplication*)));
m_iconList->append(icon);

update();
}

The requirement is i want to disable the icons but not the mwidget.....icons are used to launch certain apps.....and the icons are populating from a server and the above code is runnig in the client....is der any option?

in_dbasu
22nd July 2011, 05:55
Anybody???