我有一个自定义的QGraphicsItem实现.我需要能够限制项目的移动位置 - 即e.将其限制在某个区域.当我检查Qt文档时,这是它的建议:
QVariant Component::itemChange(GraphicsItemChange change, const QVariant &value)
{
if (change == ItemPositionChange && scene()) {
// value is the new position.
QPointF newPos = value.toPointF();
QRectF rect = scene()->sceneRect();
if (!rect.contains(newPos)) {
// Keep the item inside the scene rect.
newPos.setX(qMin(rect.right(), qMax(newPos.x(), rect.left())));
newPos.setY(qMin(rect.bottom(), qMax(newPos.y(), rect.top())));
return newPos;
}
}
return QGraphicsItem::itemChange(change, value);
}
Run Code Online (Sandbox Code Playgroud)
所以基本上,检查传递给itemChange的位置,如果你不喜欢它,更改它并返回新值.
看起来很简单,除了它实际上没有用.当我检查调用堆栈时,我看到从QGraphicsItem :: setPos调用了itemChange,但它甚至没有查看返回值.所以没有任何目的让我返回一个改变的位置,没有人在看它.请参阅QGraphicsItem.cpp中的代码
// Notify the item that the position is changing.
const QVariant newPosVariant(itemChange(ItemPositionChange, qVariantFromValue<QPointF>(pos)));
QPointF newPos = newPosVariant.toPointF();
if (newPos == …Run Code Online (Sandbox Code Playgroud) 在图标模式下使用qlistview时,我需要在选择图标时完全删除hilighting.使用下面的代码不再突出显示图标下方的文本,但选中后仍然会在图标上显示蓝色
QString stylesheet = "";
stylesheet += "QListView::item:alternate {background-image: transparent; background-color: transparent;}";
stylesheet += "QListView::item:selected {background-image: transparent; background-color: transparent;padding: 0px;color: black;}";
stylesheet += "QListView::item:selected:active{background-image: transparent;background-color: transparent; color: black;}";
stylesheet += "QListView::item:selected:!active{background-image: transparent;background-color: transparent;color: black;}";
setStyleSheet(stylesheet);
Run Code Online (Sandbox Code Playgroud)
有没有人知道如何在图标上更改所选颜色而不必继承QStandardItem?
我正在导出一个可以从非托管代码调用的方法,但该函数本身存在于托管 C++ 项目中。以下代码导致编译器错误:
error C2526: 'System::Collections::Generic::IEnumerator<T>::Current::get' : C linkage function cannot return C++ class 'System::Collections::Generic::KeyValuePair<TKey,TValue>'
error C2526: 'System::Collections::Generic::Dictionary<TKey,TValue>::KeyCollection::GetEnumerator' : C linkage function cannot return C++ class 'System::Collections::Generic::Dictionary<TKey,TValue>::KeyCollection::Enumerator'
Run Code Online (Sandbox Code Playgroud)
extern "C"
__declspec( dllexport )
bool MyMethod(std::string &name, std::string &path, std::map<std::string, std::string> &mymap)
{
System::Collections::Generic::Dictionary<System::String ^, System::String^> _mgdMap = gcnew System::Collections::Generic::Dictionary<System::String ^, System::String ^>();
// Blah blah processing
}
Run Code Online (Sandbox Code Playgroud)
稍微研究一下这个错误,这个问题通常与标记为“extern“C”的方法的定义有关。那么为什么它会关心方法内部发生的事情呢?
如果我注释掉 Dictionary 初始化,或者将它切换到 HashTable,一切都会很好地编译。
下面的方法也适用 - 如果不是在本地定义字典,我通过在方法中初始化它来避免局部变量。
bool status = CallAnotherMethod(ConvertToDictionary(mymap));
Run Code Online (Sandbox Code Playgroud)
其中 ConvertToDictionary 被声明为
System::Collections::Generic::Dictionary<System::String ^, System::String ^>^ ConvertToDictionary(std::map<std::string, std::string> &map)
{
} …Run Code Online (Sandbox Code Playgroud) 我已经下载了Qt的源代码包,并且正在尝试在64位Windows 7机器上构建64位版本.我尽可能多地阅读构建Qt的内容,但我必须在某处遗漏某些东西.
我打开一个64位命令shell,一些描述似乎认为是唯一必要的.
接下来我调用configure.但是,我应该指定一个平台选项吗?如果是这样的话?似乎没有win64选项,或类似的东西.
然后我调用nmake,它构建了一堆东西,但它仍然以32位构建.
我错过了什么?任何帮助都会很棒.