I created a NSButton grid (see picture) and setAction for each NSButton like this:
[myButton setAction:#selector(buttonPressed)];
-(void)buttonPressed { //things run here
NSLog(#"Button pressed!%#", titleString);
}
Unfortunately I donĀ“t see how to get the title of the button which was pressed. I would like to retriev the buttontitle and store it in titleString at the beginning of buttonPressed.
Any idea?
I created an IBAction to get a sender what I already tried before without success:
- (IBAction) buttonPressed:(id)sender {
NSString *titleStr = [sender title]; //getting the btn text
NSLog(#"Button '%#' pressed!", titleStr);
}
The clue ist that buttonPressed must be followed by a colon. Now it works like a charm.
[myButton setAction:#selector(buttonPressed:)];
Related
How do I recognize a double click on a tab in order to change its label?
Preferrably I could edit the label in place but alternatively I could also get a string from another input box. Any suggestions?
The tab gets added and the label specified currently like:
QString tab_label = QString("Shell (") + QString::number(session->id(), 16) + ")";
addTab(session->widget(), tab_label);
and I'd want to be able to edit the label after creation.
Oh and I should mention here that I'm a Qt newbie, too!
EDIT1
full method:
int SessionStack::addSession(Session::SessionType type)
{
Session* session = new Session(type, this);
connect(session, SIGNAL(titleChanged(int,QString)), this, SIGNAL(titleChanged(int,QString)));
connect(session, SIGNAL(terminalManuallyActivated(Terminal*)), this, SLOT(handleManualTerminalActivation(Terminal*)));
connect(session, SIGNAL(activityDetected(Terminal*)), m_window, SLOT(handleTerminalActivity(Terminal*)));
connect(session, SIGNAL(silenceDetected(Terminal*)), m_window, SLOT(handleTerminalSilence(Terminal*)));
connect(session, SIGNAL(destroyed(int)), this, SLOT(cleanup(int)));
m_sessions.insert(session->id(), session);
QString tab_label = QString("Shell (") + QString::number(session->id(), 16) + ")";
addTab(session->widget(), tab_label);
emit sessionAdded(session->id());
raiseSession(session->id());
return session->id();
}
There's a QTabBar::tabBarDoubleClicked signal, you just need to connect it to a slot to detect a double click. Also you'll need some widget to actually edit the tab's text. If you want it "out of place" (say, you open a dialog) then it should be enough to do something like:
connect(tabWidget->tabBar(), &QTabBar::tabBarDoubleClicked,
this, MyWidget::editTabBarLabel);
void MyWidget::editTabBarLabel(int tabIndex)
{
if (tabIndex < 0)
return;
// open dialog asking for the new label,
// f.i. via QInputDialog::getText
// set the new label bakc
}
If instead you want some in-place modification you'll need to more or less heavily modify QTabBar to do so.
The simplest option would be opening a QLineEdit on the right tab. To get the geometry of a tab via QTabBar:.tabrect, so that you can place the line edit in the same geometry. You'll very likely fall short on that path (see below) and you'll need to subclass QTabBar and use initStyleOption for the given tab, then set the lineedit's geometry to the right subrect (for instance, do not cover the "side widgets" of a tab).
Random pseudo braindumped code:
void MyTabBar::editTabBarLabel(int tabIndex)
{
if (tabIndex < 0)
return;
if (!m_lineEdit) {
m_lineEdit = new QLineEdit(this);
// once done, commit the change, or abort it, anyhow
// destroy/hide (?) the line edit
connect(m_lineEdit, &QLineEdit::editingFinished,
this, &MyTabBar::renameLabel);
} else {
// we're actually editing something else, what to do?
// commit the other change and start editing here?
}
m_editedTabIndex = tabIndex; // remember which one we're editing
m_lineEdit->setText(tabText(tabIndex));
// not "entirely" accurate, you need better subrect control here,
// cf. QStyle and https://doc.qt.io/qt-5/style-reference.html#widget-walkthrough
// that's why this should really be a QTabBar subclass, because
// you'll need to invoke initStyleOption and then fetch the subrects from the style
m_lineEdit->setGeometry(tabRect(tabIndex));
m_lineEdit->show();
}
// also track resize of the tabbar, relayout, tab reorder, tab insertion and removal, etc.
// move the QLineEdit accordingly
I have a button in Update panel in my page. on button click event dependendant on the text boxes entered i m buliding an url and have to open that url in new window.
i have tried:
i) window open .. but it opens un maximized , not a fully maximized window. i tried setting its height to screen hieght,,but the requirement is full window only, shouldnt need to be maximize every time i open window.
<Asp:button OnClick="Btn1_Click" />
//in code behind
protected void Btn1_Click(object sender, EventArgs e)
{
//my code to generate url
// In below lines im trying to open window
//Im ont using OnClientClick becoz..the button is in Update panel
ScriptManager.RegisterStartupScript(btnLoadReport.Page,
Btn1.GetType(), "", "window.open('" + myUrl+ "','','height=' + screen.height + ',width=' + screen.width + ',resizable=yes,scrollbar=yes,toolbar=yes,menubar=yes,location=yes,top=0, left=0');", true);
}
or can i create a hyperlink click event dynamically on button click event.. and how do i try that?
any ideas and samples would be appreciated.
Thanks,
Ahmed
try this: OnClientClick="window.open('url')"
the c# file you write,
button.attributes.add("onclick","javascript:function1()");
in the aspx page,write the below javascript function
function function1()
{
window.open("pagename",other attributes whose values are to be passed to other page);
}
Did not understand you the first time. Try this. Im guessing your not using update panels here right? cause if you are you should use scriptmanger.register.. instead of client script
Btn1_Click()
{
//my code to bulid url
ClientScript.RegisterStartupScript(this.GetType(),"Redirection","window.open('www.google.com', '_blank')",true);
}
<Asp:button OnClick="Btn1_Click" />
try this please : window.open(url, '_blank');
EDIT : look at this link dude example for opening new tab
My issue got resolved by adding 'chromemode=yes' in parameters.. like below..
window.open(url, 'chromemode=yes, scrollbars=yes' );
thank you all for your answers :)
I am trying to bind the datapoints with the onclick event, so that I could display a overlay box with some additional details and links. I'm using the .nv-point class to access the datapoints. The problem is that I'm unable to register the onclick event to those datapoints.
Here is the code :
d3.selectAll(".nv-point").on("click",function(){
alert("clicked");
//do something more
});
Here is the demo in jsFiddle
You can easily attach a click handler to the "circle", or node point on a lineChart like this:
chart.lines.dispatch.on('elementClick', function(e) {
alert("You've clicked on " + e.series.key + " - " + e.point.x);
});
In the above example, this will show the Key (of the line) and the exact x value of the node you've clicked on. I find it very helpful to set a breakpoint on the alert line, and using Chrome/FF/etc developer tools, inspect the thee object so you can see exactly what data is available and how to access it.
After much futzing around, this seems to work for me:
d3.select("#mainGraph svg").selectAll(".nv-point").style("pointer-events", "all").on("click", function( e ) { console.log( JSON.stringify( e ) ); });
Basically, the difference between what I've done and what you originally tries is just resetting overriding the stylesheet to turn on pointer-events, i.e. style("pointer-events", "all").`
The line plot is made with svg lines, which have class nv-line. A fork of your original jsFiddle is here: http://jsfiddle.net/pnavarrc/qzwkn/1/
d3.selectAll(".nv-line").on("click", function () {
alert("clicked");
});
If you feel like having a look at the source code of nvd3:
https://github.com/novus/nvd3/blob/master/src/models/lineChart.js
https://github.com/novus/nvd3/blob/master/src/models/line.js
You could just add the argument, that will link it to the data point.
In my case, I was trying to hyperlink for each data point.
The arguments has value passed, which can be used to update hyperlink as per requirement.
d3.selectAll(".nv-point").on("click", function (e) {
alert(e[0].values[0]);
});
If you have used the fullscreen mode in an instance of Galleria you've seen that the only way to close it is by pressing the escape key.
As I like that functionality since it's really practical, for end users it's not that intuitive so I would like to add a close button in the upper right.
I checked the code to find out where to add that button but I couldn't understand it to make it work.
Has someone already made that? I hope I'm not the only one who had that idea.
Thank you for your help!
You add it using the Galleria API:
Galleria.ready(function() {
var gallery = this;
this.addElement('exit').appendChild('container','exit');
var btn = this.$('exit').hide().text('close').click(function(e) {
gallery.exitFullscreen();
});
this.bind('fullscreen_enter', function() {
btn.show();
});
this.bind('fullscreen_exit', function() {
btn.hide();
});
});
This will place the close text in the upper left corner, you should of course style it with som CSS, f.ex:
.galleria-exit{position:absolute;top:12px;right:12px;z-index:10;cursor:pointer}
Greetings!
I'm calling a Web service from Javascript when a user clicks on a link. I need to get the coordinates where the user clicked so that I can display a DIV in an appropriate location. My client-side script looks like the following:
var g_event;
function DoWork(event, theId)
{
if (IsIE())
g_event = window.event;
else
g_event = event;
Acme.WebServices.Worker.GetInformation(theId, DoWorkSuccess);
}
function DoWorkSuccess(result)
{
var l_elemDiv = document.getElementById("content-area-div");
DisplayAreaDiv(g_event, l_elemDiv, result);
}
It's used like this:
Help
This works great in Firefox, Safari, and Opera. In IE7, not so much. For example, if I place the following code at the end of both the DoWork() and DoWorkSuccess() functions:
alert(g_event.clientX + ", " + g_event.clientY);
In IE, I'll get two alerts; the first one has correct coordinates, but the second one (which displays on top of the first one) is simply "[object]". Since that "[object]" one is the last one, my DIV is incorrectly displayed in the top left of the browser window. Is there a way I can prevent IE from giving me a second "bad" event? Thanks.
Why not extract and save the coordinates in DoWork and simply use them in DoWorkSuccess rather than saving the event. Of course this won't work if there is more data you are extracting from the event.
var client_x;
var client_y;
function DoWork(event, theId)
{
var g_event;
if (IsIE())
g_event = window.event;
else
g_event = event;
client_x = g_event.clientX;
client_y = g_event.clientY;
Acme.WebServices.Worker.GetInformation(theId, DoWorkSuccess);
}
function DoWorkSuccess(result)
{
var l_elemDiv = document.getElementById("content-area-div");
DisplayAreaDiv( { clientX : client_x, clientY : client_y }, l_elemDiv, result);
}
Have you tried setting window.event.cancelBubble = true in your DoWork function?
If not, quirks mode has good article on events and event bubbling - http://www.quirksmode.org/js/events_order.html that has helped me a lot with these kinds of issues.