在 pixMapItem 上覆盖鼠标事件对我不起作用;pixMapItem 未检测到鼠标单击事件。这是我的代码:
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class DrawImage( QMainWindow ):
def __init__(self, path):
QMainWindow.__init__(self)
self.setWindowTitle('Select Window')
self.local_image = QImage(path)
self.local_grview = QGraphicsView()
self.setCentralWidget( self.local_grview )
self.local_scene = QGraphicsScene()
self.image_format = self.local_image.format()
self.pixMapItem = self.local_scene.addPixmap( QPixmap(self.local_image) )
self.local_grview.setScene( self.local_scene )
self.pixMapItem.mousePressEvent = self.pixelSelect
self.show()
sys.exit(app.exec_())
def pixelSelect( self, event ):
print 'hello'
position = QPoint( event.pos().x(), event.pos().y())
color = QColor.fromRgb(self.local_image.pixel( position ) )
if color.isValid():
rgbColor = '('+str(color.red())+','+str(color.green())+','+str(color.blue())+','+str(color.alpha())+')'
self.setWindowTitle( 'Pixel position = (' …Run Code Online (Sandbox Code Playgroud) 我有这个 html 行:
<div class="hide-btn top tip-s" original-title="Close sidebar"></div>
Run Code Online (Sandbox Code Playgroud)
当用户点击它时,我希望文本更改为“打开侧边栏”,我该怎么做?
这是我的JS:
$(".hide-btn").click(function(){
if($("#left").css("width") == "0px"){
$("#left").animate({width:"230px"}, 500);
$("#right").animate({marginLeft:"250px"}, 500);
$("#wrapper, #container").animate({backgroundPosition:"0 0"}, 500);
$(".hide-btn.top, .hide-btn.center, .hide-btn.bottom").animate({left: "223px"}, 500, function() { $(window).trigger("resize");});
}
else{
$("#left").animate({width:"0px"}, 500);
$("#right").animate({marginLeft:"20px"}, 500);
$("#wrapper, #container").animate({backgroundPosition:"-230px 0px"}, 500);
$(".hide-btn.top, .hide-btn.center, .hide-btn.bottom").animate({left: "-7px"}, 500, function() { $(window).trigger("resize");});
}
});
Run Code Online (Sandbox Code Playgroud)
感谢您的时间!
我得到了带有标签按钮的输入字段
<input id="demooutput" type="text" size="15" value="My Text" name="demo" />
<span class="demooutput">
<a href="#" class="button orange"> A</a>
<a href="#" class="button orange"> B</a>
<a href="#" class="button orange"> C</a>
<a href="#" class="button orange"> D</a>
<a href="#" class="button orange"> E</a>
</span>
Run Code Online (Sandbox Code Playgroud)
使用此 jQuery 代码,我将值添加到输入
$('.demooutput a').click(function(){
$('#demooutput').val($(this).html());
return false;
});
Run Code Online (Sandbox Code Playgroud)
但我每次点击按钮都会清除我现有的价值
我想将按钮中的值另外添加到输入中的现有值
我想要的例子
My Text A (by click on A)
My Text A B (by click on A and B)
My Text B C E (by click on B, C and E)
and so …Run Code Online (Sandbox Code Playgroud) 我在 PyQT 中创建单击按钮时遇到了一些麻烦。当我创建如下按钮时,此图片无法保存
cv.SetImageROI(image, (pt1[0],pt1[1],pt2[0] - pt1[0],int((pt2[1] - pt1[1]) * 1)))
if self.Button.click():
cv.SaveImage('example.jpg', image)
cv.ResetImageROI(image)
Run Code Online (Sandbox Code Playgroud) 我正在使用类 btn1 来控制某些按钮的显示。
我设置了一个可以正常工作的点击功能
$('#rotation').on('click', '.btn1'...
Run Code Online (Sandbox Code Playgroud)
这为所有 btn1 按钮调用了相同的点击函数。
我试图弄清楚如何拥有相同的显示类,但为每个按钮调用不同的功能,例如
$('#rotation').on('click', '.btn1 process1'...
Run Code Online (Sandbox Code Playgroud)
当这个被点击
<div class="btn1 process1">
Run Code Online (Sandbox Code Playgroud)
和
$('#rotation').on('click', '.btn1 process2'...
Run Code Online (Sandbox Code Playgroud)
当这个被点击
<div class="btn1 process2">
Run Code Online (Sandbox Code Playgroud)
他们不工作。是否可以这样做,或者我是否需要为每个按钮设置 ID,并设置单击功能以侦听 ID 而不是类?
感谢您的时间和帮助。
我可以以编程方式为视图触发长按事件吗?我知道有用于触发点击事件的 performClick() 函数,但我正在寻找长按事件
我正在执行这个 JavaScript,这是一种自我解释(我认为)。一个带有类的页面上大约有 100 个按钮button,我希望它们一个一个地点击。它工作正常。
但我想在点击下一步按钮之前添加 5 秒的延迟。
var mybtn = document.getElementsByClassName('.button');
for( var i=0; i<100; i++ ) {
mybtn[i].click();
}
Run Code Online (Sandbox Code Playgroud) 我已经为页面上的某些元素定义了一个事件处理程序。
var selector = "div, select, input, button";
$(selector).on('click', function (e) {
//deactivate function of the elements and prevent propagation
e.preventDefault();
e.stopPropagation();
//...
//dialog is loaded and created here
//e.g. $(body).append('<see-dialog-html-from-below>');
//...
alert('selector click');
}
Run Code Online (Sandbox Code Playgroud)
然后我在运行时向 DOM 添加(和删除)一个对话框(一次一个对话框)。简化的对话框可能如下所示:
<div id="dialog" class="ui vertical menu">
<div class="item">
<label for="constraints">Constraints:</label>
<select id="constraints" name="constraints">
<option value="0">option 0</option>
<option value="1">option 1</option>
<option value="2">option 2</option>
<option value="3">option 3</option>
</select>
</div>
<div class="item clearfix">
<div class="ui buttons">
<div id="save_button" class="ui green button">Save</div>
<div class="or"></div>
<div id="cancel_button" class="closebutton …Run Code Online (Sandbox Code Playgroud) 我知道这个问题已被问过几次,但我似乎无法解决这个问题。当孩子被点击时,我不希望父事件触发。我有以下几点:
<div class="tabItem">
<span> Item 1</span>
<div class='contentBody'>Item 2 Body</div>
</div>
Run Code Online (Sandbox Code Playgroud)
以及以下jquery:
$(document).ready(function() {
$('.tabItem').each(function(index){
$(this).attr('id', 'tabIndex'+index);
var contentDiv = $(this).find('div').first();
var position = contentDiv.position();
var right = $(window).width() - position.left - contentDiv.width() ;
var top = (position.top - 18) ;
var contentId = 'tabContent' + index;
$(contentDiv).css( "display", "none" ).css({top: top, left: 200}).attr('id', contentId);
$(this).on('click', function() {
$(this).removeClass('tabItem').addClass('tabItemSelected');
$(currentTab).removeClass('tabItemSelected').addClass('tabItem');
if($('#' + currentContentBody).is(":visible")){
$('#' + currentContentBody).toggle( "slide" ); // close the last tab
}
if($(contentDiv).is(":hidden")){
$(contentDiv).toggle( "slide" );
}
currentTab …Run Code Online (Sandbox Code Playgroud) 假设我有一个简单的
<li (click)="clicked($event)">click me</li>
Run Code Online (Sandbox Code Playgroud)
然后如何在函数中告知事件是通过编程方式触发还是由用户触发?
可以使用jQuery收集这些信息,但是我没有机会仅使用js来实现。
click ×10
jquery ×5
javascript ×2
android ×1
angular ×1
button ×1
coordinate ×1
dom ×1
dom-events ×1
mouse ×1
pixel ×1
pyqt ×1
qt ×1
save ×1
text ×1