Originally Posted by
wysota
Ad 1. Try using the Q_PROPERTY macro with DESIGNABLE option set to false, it should make the property invisible in Designer. If you want something more complicated (like being able to enable/disable a property on a temporary basis), you'll need to access the property browser from within your Designer plugin like this:
if(form){
sheet = qt_extension<QDesignerPropertySheetExtension*>(manager, mywidget);
int propertyIndex = sheet->indexOf(propName);
sheet->setVisible(propertyIndex, false); // or true if you want to make it visible again
}
QDesignerFormWindowInterface *form = QDesignerFormWindowInterface::findFormWindow(mywidget);
if(form){
QDesignerFormEditorInterface *editor = form->core();
QExtensionManager *manager = editor->extensionManager();
QDesignerPropertySheetExtension *sheet;
sheet = qt_extension<QDesignerPropertySheetExtension*>(manager, mywidget);
int propertyIndex = sheet->indexOf(propName);
sheet->setVisible(propertyIndex, false); // or true if you want to make it visible again
}
To copy to clipboard, switch view to plain text mode
where "mywidget" is the widget you want to manipulate the property for. You can implement it in a slot connected to a signal informing about a property change (there is such a signal in
QDesignerPropertyEditorInterface).
OK, I see exactly what you are talking about. I'm still having a few issues. I implemented the following function, using the code above as a template:
//=====================================================================
// METHOD : setPropertyEditorItems()
//
// DESCRIPTION:
// Used by plugins in order to hide/show specific property editor properties
//
// PRECONDITIONS:
// A valid list of properties
//
// POSTCONDITIONS:
// NONE
//
// EXCEPTIONS:
// NONE
//
// PARAMETERS:
// pTheWidget: A Pointer to the widget whos properties in designer are to be updated
// QStringListToChange: the QStringList list of the names of property editor properties to hide or show
// bShowProperties: A bool, when true, will show the properties in QStringListToHide, when false will hide them
//
// RETURN VALUE:
// True if able to complete operation, false otherwise
//=====================================================================
bool setPropertyEditorItems
(QWidget *pTheWidget,
QStringList QStringListToChange,
bool bShowProperties
) {
bool bRetVal = false;
int iLoopVal, iPropertyIndex;
// attempting to get a pointer to the property editor control methods
if (pFormWindow && false == QStringListToChange.isEmpty())
{
bRetVal = true;
pPropertySheet = qt_extension<QDesignerPropertySheetExtension*>(pExtensionManager, pTheWidget);
// now traversing our list and setting the properties accordingly
for (iLoopVal = 0; iLoopVal < QStringListToChange.size(); iLoopVal++)
{
iPropertyIndex = pPropertySheet->indexOf(QStringListToChange[iLoopVal]);
std::cout << "Found index of " << iPropertyIndex << " for string " << QStringListToChange[iLoopVal].toStdString() << std::endl;
std::cout << "Setting value to " << bShowProperties << std::endl;
pPropertySheet->setVisible(iPropertyIndex, bShowProperties);
}
}
// reporting the results of the operation
return bRetVal;
};
//=====================================================================
// METHOD : setPropertyEditorItems()
//
// DESCRIPTION:
// Used by plugins in order to hide/show specific property editor properties
//
// PRECONDITIONS:
// A valid list of properties
//
// POSTCONDITIONS:
// NONE
//
// EXCEPTIONS:
// NONE
//
// PARAMETERS:
// pTheWidget: A Pointer to the widget whos properties in designer are to be updated
// QStringListToChange: the QStringList list of the names of property editor properties to hide or show
// bShowProperties: A bool, when true, will show the properties in QStringListToHide, when false will hide them
//
// RETURN VALUE:
// True if able to complete operation, false otherwise
//=====================================================================
bool setPropertyEditorItems(QWidget *pTheWidget, QStringList QStringListToChange, bool bShowProperties)
{
bool bRetVal = false;
int iLoopVal, iPropertyIndex;
QDesignerFormWindowInterface *pFormWindow = 0;
// attempting to get a pointer to the property editor control methods
pFormWindow = QDesignerFormWindowInterface::findFormWindow(pTheWidget);
if (pFormWindow && false == QStringListToChange.isEmpty())
{
bRetVal = true;
QDesignerFormEditorInterface *pFormEditor = pFormWindow->core();
QExtensionManager *pExtensionManager = pFormEditor->extensionManager();
QDesignerPropertySheetExtension *pPropertySheet;
pPropertySheet = qt_extension<QDesignerPropertySheetExtension*>(pExtensionManager, pTheWidget);
// now traversing our list and setting the properties accordingly
for (iLoopVal = 0; iLoopVal < QStringListToChange.size(); iLoopVal++)
{
iPropertyIndex = pPropertySheet->indexOf(QStringListToChange[iLoopVal]);
std::cout << "Found index of " << iPropertyIndex << " for string " << QStringListToChange[iLoopVal].toStdString() << std::endl;
std::cout << "Setting value to " << bShowProperties << std::endl;
pPropertySheet->setVisible(iPropertyIndex, bShowProperties);
}
}
// reporting the results of the operation
return bRetVal;
};
To copy to clipboard, switch view to plain text mode
For a test case, I call the method above from another object in the following way:
QStringListToChange << "myfakestuff" << "geometry" << "enabled" << "sizePolicy" << "buttonSize";
setPropertyEditorItems(this, QStringListToChange, false);
QString QStringListToChange;
QStringListToChange << "myfakestuff" << "geometry" << "enabled" << "sizePolicy" << "buttonSize";
setPropertyEditorItems(this, QStringListToChange, false);
To copy to clipboard, switch view to plain text mode
This is the output I see on the terminal (running Qt 4.1.2 on linux, btw):
Found index of -1 for string myfakestuff
Setting value to 0
Found index of 4 for string geometry
Setting value to 0
Found index of 3 for string enabled
Setting value to 0
Found index of 17 for string sizePolicy
Setting value to 0
Found index of 54 for string buttonSize
Setting value to 0
So from the output I know that all the property names I am using appear to be valid (except for myfakestuff, which is not a valid name, I put it in to test what would happen). Btw buttonSize is a custom property I specified with Q_PROPERTY(). Finally, here a screenshot of what the property editor looks like AFTER I start a blank form and drag my custom widget into it. Shouldn't the properties above not be visible?
Bookmarks