C++ 类似Qt Creator选项选项卡的对话框的示例代码
我想建立一个与Qt Creator“选项”选项卡相同的对话框,左侧页面标题为滚动条,右侧为详细页面 如果有代码示例或示例应用程序可供参考,这将非常有用 提前感谢Qt Creator源代码 Qt Creator在Gitorious和GitHub中都有它的源代码。但由于QtCreator是一个如此庞大而复杂的项目,它可能无法找到它的子部分 Github版本非常易于搜索。最后,与Qt Creator中的nice options页面相关的源代码使用C++ 类似Qt Creator选项选项卡的对话框的示例代码,c++,qt,user-interface,dialog,options,C++,Qt,User Interface,Dialog,Options,我想建立一个与Qt Creator“选项”选项卡相同的对话框,左侧页面标题为滚动条,右侧为详细页面 如果有代码示例或示例应用程序可供参考,这将非常有用 提前感谢Qt Creator源代码 Qt Creator在Gitorious和GitHub中都有它的源代码。但由于QtCreator是一个如此庞大而复杂的项目,它可能无法找到它的子部分 Github版本非常易于搜索。最后,与Qt Creator中的nice options页面相关的源代码使用IOptionsPage作为选项对话框中显示的任何页面的
IOptionsPage
作为选项对话框中显示的任何页面的基类
ioptionspage.cpp
包含解释不同插槽用途的所有注释
基本上,对于Qt Creators选项页面,它有一个由多个不同子模块使用的接口
\ifndef IOPTIONSPAGE\H
#定义IOPTIONSPAGE_H
#包括
#包括
#包括
#包括
名称空间核心{
类核心\u导出IOptionsPage:公共QObject
{
Q_对象
公众:
IOptionsPage(QObject*parent=0);
虚拟~IOptionsPage();
Id Id()常量{return m_Id;}
QString displayName()常量{return m_displayName;}
Id category()常量{return m_category;}
QString displayCategory()常量{return m_displayCategory;}
QIcon categoryIcon()常量{return QIcon(m_categoryIcon);}
虚拟布尔匹配(常量QString和searchKeyWord)常量;
虚拟QWidget*widget()=0;
虚空应用()=0;
虚拟void finish()=0;
受保护的:
void setId(Id){m_Id=Id;}
void setDisplayName(const QString&displayName){m_displayName=displayName;}
void setCategory(Id category){m_category=category;}
void setDisplayCategory(const QString&displayCategory){m_displayCategory=displayCategory;}
void setCategoryIcon(const QString&categoryIcon){m_categoryIcon=categoryIcon;}
Id m_Id;
Id m_类;
QString m_displayName;
QString m_显示类别;
QString m_categoryIcon;
可变布尔m_关键字中国化;
可变QStringList m_关键词;
};
/*
提供选项页而不是添加IOptionsPage的替代方法
对象放入插件管理器池。仅当创建
在Qt Creator启动时,实际选项页不可能或太贵。
(就像设计器集成一样,它需要初始化设计器插件
在选项页面可用之前。)
*/
类核心\u导出IOptionsPageProvider:公共QObject
{
Q_对象
公众:
IOptionsPageProvider(QObject*parent=0):QObject(parent){}
Id category()常量{return m_category;}
QString displayCategory()常量{return m_displayCategory;}
QIcon categoryIcon()常量{return QIcon(m_categoryIcon);}
虚拟QList页面()常量=0;
虚拟布尔匹配(常量QString&/*searchKeyWord*/)常量=0;
受保护的:
void setCategory(Id category){m_category=category;}
void setDisplayCategory(const QString&displayCategory){m_displayCategory=displayCategory;}
void setCategoryIcon(const QString&categoryIcon){m_categoryIcon=categoryIcon;}
Id m_类;
QString m_显示类别;
QString m_categoryIcon;
};
}//名称空间核心
#endif//IOPTIONSPAGE_H
搜索框使用一个索引,该索引包含添加的每个选项页的子项的所有标题/标签
bool Core::IOptionsPage::matches(const QString &searchKeyWord) const
{
if (!m_keywordsInitialized) {
IOptionsPage *that = const_cast<IOptionsPage *>(this);
QWidget *widget = that->widget();
if (!widget)
return false;
// find common subwidgets
foreach (const QLabel *label, widget->findChildren<QLabel *>())
m_keywords << label->text();
foreach (const QCheckBox *checkbox, widget->findChildren<QCheckBox *>())
m_keywords << checkbox->text();
foreach (const QPushButton *pushButton, widget->findChildren<QPushButton *>())
m_keywords << pushButton->text();
foreach (const QGroupBox *groupBox, widget->findChildren<QGroupBox *>())
m_keywords << groupBox->title();
// clean up accelerators
QMutableStringListIterator it(m_keywords);
while (it.hasNext())
it.next().remove(QLatin1Char('&'));
m_keywordsInitialized = true;
}
foreach (const QString &keyword, m_keywords)
if (keyword.contains(searchKeyWord, Qt::CaseInsensitive))
return true;
return false;
}
bool-Core::IOptionsPage::matches(const-QString&searchKeyWord)const
{
如果(!m_关键字中国化){
IOptionsPage*that=const_cast(this);
QWidget*widget=那个->widget();
如果(!小部件)
返回false;
//查找公共子窗口小部件
foreach(常量QLabel*标签,小部件->findChildren())
m_关键字text();
foreach(const QCheckBox*复选框,小部件->findChildren())
m_关键字text();
foreach(const QPushButton*按钮,小部件->findChildren())
m_关键字text();
foreach(const QGroupBox*groupBox,widget->findChildren())
m_关键字title();
//清洁加速器
QMutableStringListIterator(m_关键字);
while(it.hasNext())
it.next().remove(QLatin1Char('&');
m_关键字sinitialized=true;
}
foreach(常量QString&关键字,m_关键字)
if(keyword.contains(searchKeyWord,Qt::case不敏感))
返回true;
返回false;
}
查找原始对话框的其余组件可能需要一些时间,但这是可行的
包括示例
在Qt Creator>Welcome(tab)>Examples
中,对于复杂的设置对话框,最好的方法可能是:
选项卡对话框示例
持久设置
QSettings
可能是存储设置的最佳选择。其他选项包括XML
和JSON
。Qt5有一个很棒的JSON
实现
希望对您有所帮助。Qt Creator源代码
Qt Creator在Gitorious和GitHub中都有它的源代码。但由于QtCreator是一个如此庞大而复杂的项目,它可能无法找到它的子部分
Github版本非常易于搜索。最后,与Qt Creator中的nice options页面相关的源代码使用IOptionsPage
作为选项对话框中显示的任何页面的基类
ioptionspage.cpp
包含解释不同插槽用途的所有注释
基本上,对于Qt Creators选项页面,它有一个由多个不同子模块使用的接口
\ifndef IOPTIONSPAGE\H
#定义IOPTIONSPAGE_H
#包括
#包括
#包括
#包括
名称空间核心{
类核心\u导出IOptionsPage:公共QObject
{
Q_对象
公众:
bool Core::IOptionsPage::matches(const QString &searchKeyWord) const
{
if (!m_keywordsInitialized) {
IOptionsPage *that = const_cast<IOptionsPage *>(this);
QWidget *widget = that->widget();
if (!widget)
return false;
// find common subwidgets
foreach (const QLabel *label, widget->findChildren<QLabel *>())
m_keywords << label->text();
foreach (const QCheckBox *checkbox, widget->findChildren<QCheckBox *>())
m_keywords << checkbox->text();
foreach (const QPushButton *pushButton, widget->findChildren<QPushButton *>())
m_keywords << pushButton->text();
foreach (const QGroupBox *groupBox, widget->findChildren<QGroupBox *>())
m_keywords << groupBox->title();
// clean up accelerators
QMutableStringListIterator it(m_keywords);
while (it.hasNext())
it.next().remove(QLatin1Char('&'));
m_keywordsInitialized = true;
}
foreach (const QString &keyword, m_keywords)
if (keyword.contains(searchKeyWord, Qt::CaseInsensitive))
return true;
return false;
}