How do i remove the selection drawing from a Qt QGraphicsTextItem - windows

I am developing a Qt 4.8 application using QGraphicsScene on Windows XP.
When the user double clicks on a QGraphicsTextItem, i call
textItem->setTextInteractionFlags(Qt::TextEditorInteraction);
At the next selection change i call
textItem->setTextInteractionFlags(Qt::NoTextInteraction);
This works correctly, but i find no way to remove the inversion of the background color that remains from editing. In the screen shot below, i first double clicked on the first text item and selected the characters "2927". Then i clicked on the second test item and selected "est". I find no way to get rid of the still inverted "2927" in the first text item (although its not in edit mode anymore).
I also tried to call:
textItem->textCursor().clearSelection();
textItem->update();
textItem->setTextInteractionFlags(Qt::NoTextInteraction);
textItem->clearFocus();
But his does not at all change the behavior.
So now i found a workaround:
QString s = textItem->toPlainText();
textItem->setPlainText("");
textItem->setPlainText(s);
textItem->setTextInteractionFlags(Qt::NoTextInteraction);
I dont like that, but it works.
Any hint for a cleaner solution?

Since QGraphicsTextItem::textCursor() returns a copy of the cursor, you have to set it back to the text item for it to have any effect.
QTextCursor cursor(textItem->textCursor());
cursor.clearSelection();
textItem->setTextCursor(cursor);

Related

Drag and Drop( ctrl+drag) Problems in Xcode

There are two places within Xcode (version 13.3) where I can't drag and drop anymore.
Trying to move a file to a Group. I have tried just clicking and dragging, control-click, option-click, command-click, none work. Instead of dragging the file, the cursor just moves without the selected/highlighted file and highlights whatever file or group it is hovering over.
Trying to drag a button to a View Controller to make a connection. Instead, a popup window appears with three rows, each with corresponding icon, two lines each (title and object type): View Controller, View, Button. (I can't figure out how to capture that screen since I am already holding the control key and mouse button (track pad) but here is a photo.
Update:. All works fine when using a mouse but these two problems always exist when using the trackpad. I did discover that by pressing the Escape key, I can perform the control-drag (but not move files). I have played with the trackpad settings but have not yet been able to figure out how to get rid of that window that appears.
This popup appears whether I am holding the control, option, or command key.
What xcode version are you using, just tried
#1 is working as expected on my xcode13.0
#2 seems to be working for me too..

wxWidgets pprogrammaticaly move to next input control

I originally had code that set the focus to the first widget in a dialog, in the onInit method. But there were problems with it: if I pressed TAB, indeed focus moved to next control (wxTextCtrl), which got the blue 'focus' color, but the 'focus' color/highlight was not removed from previous focus widget. So now it looked like both first and second control had focus at the same time...
When cycling manually (by pressing TAB) full circle (till last control and then wrap around to the first), suddenly all worked well. That is, when moving focus from first control to next one, the first visually lost focus (blue color was removed) as it should. From now on, only one item had the focus color/highlight.
So instead of setting focus on the first control, I tried a different approach: I set the focus to the last control in the dialog, which is always the OK button. Next, I want to emulate programmatically that a TAB is pressed and received by the dialog. So I wrote this (inside Dialog::onInit):
m_buttonOK->SetFocus();
wxKeyEvent key;
key.SetEventObject(this);
key.SetEventType(wxEVT_CHAR);
key.m_keyCode=WXK_TAB;
ProcessWindowEvent(key);
Now the focus indeed moves away from the OK button, but it does not wrap around to the first control.
Only when I manually press TAB after the dialog opened, the first item gets focus.
Question: why does this wrapping around to set focus on first widget not work with the code shown above?
First of all, your initial problem is almost certainly related to not calling event.Skip() in one of your event handlers, see the note in wxFocusEvent documentation.
Second, you can't send wx events to the native windows, they don't know anything about it. In this particular case you can use wxWindow::Navigate() to do what you want, but generally speaking what you're doing simple can't, and won't, work reliably.

How is this popup message created / programmed?

I recently noticed the following popup message ("6 occurrences replaced") in Qt Creator (3.4.2).
I like its style and want to use it in my own application. But how is it done? Is this a particular widget or what else? Can someone point me in the right direction.
You could create your own window with round corners like that with text in the middle paid show it when you want too make the window so it takes a parameter text and you can add different text each time and show

Messagebox centered to parent Window / Form

I am trying to build my own HTA right now to act as a front end for some of my batch scripts. I would like to use a msgbox (or anything equivalent) that I can use to output any errors, clicking Ok will just get rid of the prompt.
Here is the code I have been using:
x=msgbox("Error text" ,48, "Error: Title")
I would preferably like the following conditions, to be able to use a custom icon, the box to center on X and Y to the parent window/form, and to allow me to define the text in the box and it's title.
If this is not possible then just a messagebox that can be centered on X and Y to the parent window would suffice.
Is there any way of doing this in VBScript?
Or should I look into doing an HTML/CSS version that would popup on the screen?
I don't know the answer to your first question, but whatever the answer is there must be necessarily limits to what a box message box that pops up outside of the HTML can do.
So for customization that includes icon, centering and anything else expressible in HTML/CSS, I think you should do HTML/CSS that pops up on the screen.
You might want to look at jqueryui or bootstrap to get you going faster so you don't have to start from scratch.
https://jqueryui.com/dialog/#modal-message
http://getbootstrap.com/javascript/#modals
They both use jquery underneath so if you aren't already using it, you'll pick up some more bytes in your initial download.

GTK - Don't highlight buttons on select / hover

I'm trying to write a kiosk GUI in ruby/gtk on ubuntu. I'm pretty fluent in ruby, but new to writing GUIs and not great with linux.
I'm using a touch screen, and am using our own images for buttons, e.g.
button_image = Gtk::Image.new(Gdk::Pixbuff.new "images/button_image.png")
#button = Gtk::Button.new
#button.add(button_image)
#button.set_relief(Gtk::RELIEF_NONE)
My issue is that when the buttons are pressed or remain selected (or hovered over, although this is less relevant with a touch screen), gtk shows fat, square borders around them. Obviously it's applying gtk's prelight / selected / active lighting to the buttons. I've tried changing the button properties in various ways, and also tryied hacking apart my theme, and while I can modify how the highlighting looks, I can't seem to completely get rid of it. Changing the color of the highlight via my theme is easy, but if I remove my setting there's still a default I can't get rid of.
Does anyone know if there's a way to stop it, or possibly make it transparent? Thanks in advance!
Sounds like you want to use exactly your image for the whole button, instead of putting an image inside the normal GtkButton - but still use all the normal behavior of the button.
The easiest way to do this is to just override the drawing. If you are on gtk2, connect to the "expose-event" signal, do your drawing there, and return true so that the default handler doesn't get run. If you are on gtk3, connect to the "draw" signal and do the same.
I tried meddling with the drawing as Federico suggested, but found that the most direct way to address this was instead to use an event box rather than a button. Event boxes accept clicks just like buttons, but don't respond to selecting, hovering, etc. In ruby, the code looks like this:
image = Gtk::Image.new("myfile.png")
event_box = Gtk::EventBox.new.add(image)
event_box.visible_window = false
event_box.signal_connect("button_press_event") do
puts "Clicked."
end
Most of this is exactly like a button; the *visible_window* method, obviously, keeps the event box from being visible under the button image.

Resources