我遇到以下问题,
当为 Windows 资源管理器的上下文菜单添加条目并且 Windows 7 设计设置为经典时,图标会破坏菜单的对齐方式。
此图显示添加条目之前的菜单(请注意 Microsoft Security Essentials 的图标):

添加菜单项后,它看起来像这样:

您会看到 Microsoft Security Essentials 的图标和菜单标题之间有一个空格。使用的位图是标准 bmp 16 x 16。
有谁知道为什么会发生这种情况?再说一遍,这只发生在 Win 7 经典设计中,其他设计也能按预期工作。
在此先感谢您的帮助
编辑:
这是我添加该项目的初始代码:
iconHandle = LoadImageW(NULL, iconPath.c_str(), IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE | LR_LOADTRANSPARENT | LR_LOADFROMFILE);
MENUITEMINFOW contextEntryAppSuite = { sizeof(contextEntryAppSuite) };
contextMenuItem.fMask = MIIM_STRING | MIIM_STATE | MIIM_BITMAP | MIIM_FTYPE | MIIM_ID;
contextMenuItem.dwTypeData = caption;
contextMenuItem.wID = 0;
contextMenuItem.fType = MFT_STRING;
contextMenuItem.fState = MFS_ENABLED;
contextMenuItem.hbmpItem = static_cast<HBITMAP>(iconHandle);
if(!InsertMenuItemW(hMenu, indexMenu, TRUE, &contextMenuItem))
{
return HRESULT_FROM_WIN32(GetLastError()); …Run Code Online (Sandbox Code Playgroud) 我有一个矩形。它rectangle有一个自定义(只是在其中contextmenu进行了一些简单的更改)。我想要的是,单击鼠标左键,将弹出。ControlTemplae<ContextMenu.Template>contextmenu
我尝试添加rectangle1.contextmenu.isopen=true矩形的事件。是的,它MouseDown会打开。但是,它被设置为在矩形的上方(顶部)打开/弹出,我通过简单地添加到矩形的 XAML 来做到这一点。但是如果我在矩形的事件,然后弹出,但在错误的位置,它不再停留在顶部,而是跟随鼠标。例如,如果我单击矩形的右角,则在右侧打开/弹出。这行为很奇怪,我不知道为什么会发生这种情况。contextmenucontextmenuContextMenuService.Placement="top"rectangle1.contextmenu.isopen=trueMouseDowncontextmenucontextmenu
无论如何,如何contextmenu通过单击鼠标左键打开矩形顶部的 ?
更新
奇怪的是,无论我向其中任何一个添加什么代码mouseevent,上下文菜单都会丢失它的位置!例如,如果我什至添加MsgBox("abc")mouseDown 事件,然后右键单击矩形,上下文菜单就不在顶部!
QTableView我在 a 中有两个s QMainWindow,我想在其中一个上创建一个上下文菜单,然后在另一个上创建另一个上下文菜单。
到目前为止,创建上下文菜单并定义操作是有效的。但上下文菜单会在整个应用程序内的任何地方弹出。我不知道如何将其限制为只有一张特定的表。contextMenuEvent()我认为这与的成员有关,QMainWindow但我不知道如何更改这部分。尝试创建一个继承的自定义类QTableView不起作用,因为我不确定从哪里开始。
这是我尝试过的:
和populate_table_1()方法populate_table_2()仅用于将一些数据填充到表中。该get_selected_item_TV1()方法从一行中获取必要的数据table_1。该delete_file()方法是我在从该方法调用删除操作时想要执行的操作的示例contextMenuEvent()。到目前为止,此代码有效,但我希望仅当我右键单击一行时才弹出上下文菜单table_1,并且在右键单击其他地方时它根本不会出现。
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
data_1 = ["file_name", "file_infos"]
data_2 = ["other_stuff_1", "other_stuff_2"]
class Ui_MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setWindowTitle("MyApp")
self.resize(450, 280)
centralwidget = QWidget(self)
#]===================================================================[#
# table_1
table_1 = QTableView(
centralwidget,
selectionBehavior=QAbstractItemView.SelectRows,
editTriggers=QAbstractItemView.NoEditTriggers
)
# table_1 models
self.modelTV1 = QStandardItemModel(0, 2, …Run Code Online (Sandbox Code Playgroud) 假设您有一个图像的上下文菜单,长按时会弹出该图像。如何使弹出窗口更大,但保持相同的尺寸?
ViewControllerTableViewCell: UITableViewCell, UIContextMenuInteractionDelegate {
func contextMenuInteraction(_ interaction: UIContextMenuInteraction, configurationForMenuAtLocation location: CGPoint) -> UIContextMenuConfiguration? {
UIContextMenuConfiguration(identifier: nil, previewProvider: nil) { _ in
let share = UIAction(title: "", image: UIImage(systemName: "")) { _ in
// share code
}
return UIMenu(title: "", children: [share])
}
}
Run Code Online (Sandbox Code Playgroud)
override func awakeFromNib() {
super.awakeFromNib()
immy.isUserInteractionEnabled = true
immy.addInteraction(UIContextMenuInteraction(delegate: self))
}
Run Code Online (Sandbox Code Playgroud) contextmenu uiimageview firebase swift uicontextmenuinteraction
我正在尝试将上下文菜单与 UIViewRepresentable 一起使用。当上下文菜单被激活时,UIViewRepresentable 消失。
这是代码:
UIView可表示的视图:
struct TestView: UIViewRepresentable {
func makeUIView(context: Context) -> some UIView {
let view = UIView(frame: CGRect(x: 0, y: 0, width: 150, height: 150))
view.backgroundColor = UIColor.red
return view
}
func updateUIView(_ uiView: UIViewType, context: Context) {
//
}
}
Run Code Online (Sandbox Code Playgroud)
内容查看:
struct ContentView: View {
var body: some View {
TestView()
.frame(width: 200, height: 200)
.contextMenu {
Text("Context Menu")
}
}
}
Run Code Online (Sandbox Code Playgroud)
如何让UIViewRepresentable不消失?
我在控件上显示上下文相关菜单时遇到问题当选择多行时单击桌面视图.选择单行然后单击控件时,它工作正常.我实现这个的方式如下所示:
-(void)doSingleClick
{
NSLog(@"single clicked");
if([[NSApp currentEvent] modifierFlags] & NSControlKeyMask)
{
NSLog(@"control clicked.......");
[NSMenu popUpContextMenu:[self showContextMenu] withEvent:[NSApp currentEvent] forView:tableView];
return;
}
}
Run Code Online (Sandbox Code Playgroud)
和showContextMenu函数返回一个NSMenu对象.
我这样做是因为我的表视图出于某种奇怪的原因无法识别mouseDown或mouseUp或menuForEvent事件.
上面代码段的问题是,当选择多行并单击控件时,它无法识别控件单击并且不会进入该循环,因此不显示上下文菜单.
请建议我实现这一目标的机制.
谢谢
我有一个从sqllite查询并将输出显示为xml的活动
这是活动的一部分
( (TextView) view.findViewById(R.id.tv_id) ).setText( listItem.getId()+"");
( (TextView) view.findViewById(R.id.tv_name) ).setText( listItem.getName() );
( (TextView) view.findViewById(R.id.tv_age) ).setText( listItem.getAge()+"" );
Run Code Online (Sandbox Code Playgroud)
这是xml:
<TableLayout
android:layout_width="wrap_content"
android:id="@+id/TableLayout01"
android:layout_below="@+id/tv_age"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/tv_name">
<TableRow
android:layout_width="wrap_content"
android:layout_below="@+id/tv_age"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/TableLayout01"
android:id="@+id/TableRow01">
<TextView
android:layout_width="10dip"
android:layout_height="30dip"
android:id="@+id/tv_id"
android:text=""
android:layout_centerVertical="true">
</TextView>
<TextView
android:layout_width="100dip"
android:layout_height="wrap_content"
android:text="" android:id="@+id/tv_name"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/tv_id"
android:layout_marginLeft="10px">
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" android:id="@+id/tv_age"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/tv_name"
android:layout_marginLeft="10px">
</TextView>
</TableRow>
</TableLayout>
Run Code Online (Sandbox Code Playgroud)
现在这很好用.它显示生成的查询.现在,我想创建另一个活动,在显示查询时响应长按或只触摸一次.如何获取按下的textview的ID,以便我可以将其用于其他活动?
非常感谢您的帮助.
我有一个viewFlipper在每个"翻转"中有不同的ListViews.我已经制作了所有列表registerForContextMenu(chosenList);,并且longPress菜单出现在我想要的每个列表中.
现在我希望在不同的列表视图中有不同的contextMenues.例如.一个清单,网络信息将与网络相关的选择,在文本菜单和朋友列表会有另一组选择在它的文本菜单.
我该如何有效地做到这一点?这有可能吗?
public void onCreateContextMenu(ContextMenu menu2, menu3, menu4, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu2, menu3, menu4, v, menuInfo);
menu2.setHeaderTitle("Quick Menu");
menu3.setHeaderTitle("Menu3");
menu4.setHeaderTitle("Menu4");
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.context_menu, menu2);
inflater.inflate(R.menu.context_menu3, menu3);
inflater.inflate(R.menu.context_menu4, menu4);
}
Run Code Online (Sandbox Code Playgroud)
...要么 ...?能怎样?这开始让我在中脑疯狂......:D
我试图找到一种方法,我可以changed在加载动态上下文菜单(右键单击)时抑制jstree中的事件.我知道您可以在上下文菜单中禁止select_node事件,但我需要获取我右键单击的节点的节点ID.(因此需要使用select_node).我知道你可以在定期打电话时压制这个改变的事件select_node,但我不确定如何在右键点击时这样做.我在上下文菜单中尝试了以下操作select_node,但它不起作用:
$(function () {
$('#myTree').jstree({
"core": {
"themes": {
"variant": "small",
"icons": false
}
},
"contextmenu": {
"items": reportMenu(node), //builds context menu based on selected node
},
"plugins": ["contextmenu", "changed"]
});
});
$("#myTree").bind('select_node.jstree', function (event, data) {
// Does not work, changed event still fires.
$("#myTree").jstree().select_node(data.node.id, true);
});
Run Code Online (Sandbox Code Playgroud)
我正在寻找可能的替代方案之一:
changed在上下文菜单调用时抑制事件select_node?select_node事件的情况下获取我正确点击的节点的id (即如果我将上下文菜单设置为'select_node': false,如何捕获select节点)?contextmenu ×10
android ×2
c# ×2
c++ ×1
cocoa ×1
explorer ×1
firebase ×1
gtk# ×1
icons ×1
javascript ×1
jquery ×1
jstree ×1
listview ×1
pyqt5 ×1
python ×1
qtableview ×1
swift ×1
swiftui ×1
uiimageview ×1
wpf ×1