QCompleter not support up and down key - c++

I use setEditable(true) to make QComboBox editable, when I input cy, then the completer's popup view will be visible and lists all possible results like: cyan, cyana, liecyan ... But when I press Down in keyboard (Qt::Key_Down), the first one cyan will be selected and QComboBox's lineedit's text will be set cyan , meanwhile, completer's popup view updates, only cyan shows. How can I customize it to make it behave like web's select component.

I have solved this question.
1.class MyListView : public QListView
2.MyListView's bool event(...) need to be implemented to concern about type is QEvent::ShortcutOverride
3.based on QEvent::ShortcutOverride, when user press Qt:Key_Up or Qt::Key_Down,setfalg false, when user release key,set flag true
3.QCompleter use setPopup(MyListView's instance) to override default listview
4. set QCompleter's regexp to work when falg is true
5.I got what I want

Related

Acumatica - How to change the page opened by the edit button (pencil)

I'm trying to customize a page so that the edit button (the pencil icon one) directs the user to a specific page. In my case, the edit button is linked to a BAccountID field :
By default, it opens the Business Account's page (page CR303000):
I would like it to open a different page that I created that has a similar BAccount view (page AR303001) :
Can this be done ? And how ? I can't seem to find the code behind this logic.
The target graph is declared in the PXPrimaryGraph attribute decorating the DAC.
BAccount DAC is a special case that uses a more complex attribute (CRCacheIndependentPrimaryGraphList) that inherits from PXPrimaryGraph.
[CRCacheIndependentPrimaryGraphList(new Type[]{
typeof(CR.BusinessAccountMaint),
typeof(EP.EmployeeMaint),
typeof(AP.VendorMaint),
typeof(AP.VendorMaint),
typeof(AR.CustomerMaint),
typeof(AR.CustomerMaint),
typeof(AP.VendorMaint),
typeof(AR.CustomerMaint),
typeof(CR.BusinessAccountMaint)},
new Type[]{
typeof(Select<CR.BAccount, Where<CR.BAccount.bAccountID, Equal<Current<BAccount.bAccountID>>,
And<Current<BAccount.viewInCrm>, Equal<True>>>>),
typeof(Select<EP.EPEmployee, Where<EP.EPEmployee.bAccountID, Equal<Current<BAccount.bAccountID>>>>),
typeof(Select<AP.VendorR, Where<AP.VendorR.bAccountID, Equal<Current<BAccount.bAccountID>>>>),
typeof(Select<AP.Vendor, Where<AP.Vendor.bAccountID, Equal<Current<BAccountR.bAccountID>>>>),
typeof(Select<AR.Customer, Where<AR.Customer.bAccountID, Equal<Current<BAccount.bAccountID>>>>),
typeof(Select<AR.Customer, Where<AR.Customer.bAccountID, Equal<Current<BAccountR.bAccountID>>>>),
typeof(Where<CR.BAccountR.bAccountID, Less<Zero>,
And<BAccountR.type, Equal<BAccountType.vendorType>>>),
typeof(Where<CR.BAccountR.bAccountID, Less<Zero>,
And<BAccountR.type, Equal<BAccountType.customerType>>>),
typeof(Select<CR.BAccount,
Where2<Where<
CR.BAccount.type, Equal<BAccountType.prospectType>,
Or<CR.BAccount.type, Equal<BAccountType.customerType>,
Or<CR.BAccount.type, Equal<BAccountType.vendorType>,
Or<CR.BAccount.type, Equal<BAccountType.combinedType>>>>>,
And<Where<CR.BAccount.bAccountID, Equal<Current<BAccount.bAccountID>>,
Or<Current<BAccount.bAccountID>, Less<Zero>>>>>>)
},
VerifyRightsBy = new [] { typeof(CR.BusinessAccountMaint) })]
There is no way to easily customize this attribute. To change it would you need to replace the BAccount DAC with another one. The preferred method for your use case is to avoid usage PXPrimaryGraph attribute by using a regular action button.
The action button can be configured to show the pencil icon:
Make PXButton appear as pencil icon
And it can be displayed beside the field using PXLayout Merge property or you can use LinkCommand to redirect:
https://stackoverflow.com/a/60446714/7376238

Behavioral discrepancy in Tkinter listbox, arrow keys vs. mouse click

My environment is Python 2.7, running on Windows 7.
I'm trying get a Tkinter Listbox to trigger a callback in response to the user changing the 'active' item (i.e. the item with focus). I'm using a binding to the <<ListboxSelect>> event to make this happen, and it's working -- sort of.
The callback itself is supposed to check what the new active item is, and carry out some processing accordingly. This logic operates the way I expect when I change the active item via the up/down arrow keys. But when I point & click on a new item instead, the code mistakenly identifies the prior active item as the current one.
Here's a stripped-down code sample that illustrates the behavior I'm getting:
import Tkinter as tk
#Root window
root = tk.Tk()
#Callback to show focus change
def updateDisplay(*args):
focusIndex = str(lb.index(tk.ACTIVE))
ctrlFI.set('Focus is at index '+focusIndex)
#Control variables
ctrlLB = tk.StringVar()
ctrlFI = tk.StringVar()
#Widgets
lb = tk.Listbox(root,
width=20, height=10,
relief=tk.FLAT,highlightthickness=0,
selectmode=tk.EXTENDED,
activestyle='dotbox',
listvariable=ctrlLB)
lbl = tk.Label(root,
justify=tk.LEFT, anchor=tk.W,
textvariable=ctrlFI)
lb.grid(row=0,column=0,sticky=tk.NW,padx=(5,0),pady=5)
lbl.grid(row=1,column=0,columnspan=2,sticky=tk.NW,padx=5,pady=5)
#Listbox binding to trigger callback
lb.bind('<<ListboxSelect>>',updateDisplay)
#Initializations to prep GUI
ctrlLB.set('Index0-entry Index1-entry Index2-entry Index3-entry Index4-entry')
ctrlFI.set('Ready')
#Begin app
tk.mainloop()
Here are the results when you use the arrow keys:
But here's what you get when you click with the mouse:
The information 'lags' one behind, showing the prior selection instead. (If you click the same item a second time, it 'catches up.')
So my questions are:
What is causing the discrepancy?
How do I fix it so the mouse click gives the right result?
The active item is not necessarily the same as the selected item. When you press the mouse down it changes the selected value but it does not change the active item. The active item only changes once you release the mouse button.
You should be able to see this by clicking and holding the mouse button over an item that is not currently selected. When you do, you'll see something like this:
In the above image, the active item is the one surrounded by a dotted outline. The selected item is in blue. When your code displays the 'focus', it's displaying the active element rather than the selected element.
If you want the selected item, you need to use curselection to get the index of the selected item. It returns a tuple, so in extended mode you need to get the first element that is returned (eg: lb.curselection()[0]). Be sure to handle the case where curselection returns an empty string.

How to insert hyperlink without underline to Win32 RichEdit?

I added a link to RichEdit, use CFM_LINK/CHARFORMAT2 structure. But I can't figure out how to remove the underline effect. I tried:
SendMessage(richEditHWND, EM_AUTOURLDETECT, FALSE, NULL);
SendMessage(richEditHWND, EM_SETEDITSTYLEEX, 0, SES_EX_HANDLEFRIENDLYURL);
CHARFORMAT2 cf2;
memset(&cf2, 0, sizeof(CHARFORMAT2));
cf2.dwMask = CFM_LINK| CFM_UNDERLINE | CFM_COLOR | CFM_LINKPROTECTED;
cf2.dwEffects = CFE_LINK| CFE_UNDERLINE | CFE_LINKPROTECTED;
cf2.crTextColor = RGB(255, 0, 0);
cf2.bUnderlineType = CFU_UNDERLINENONE;
SendMessage(richEditHWND, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf2);
But it don'n work.
Another way is set underline color to white color, which is the RichEdit background color, but it is a hacky way, make character like q, j,... being cut apart, also show the line when select text.
So what's the correct way to do this?
Note: I'm using RICHEDIT50W class.
You can do this using a friendly-name hyperlink. These let you specify arbitrary text (along with its own color and formatting) that is used for display, and the actual URL is hidden.
By default, friendly-name hyperlink text is also displayed in blue
with a blue underline unless the name text is formatted with an
explicit color. Explicit formatting takes precedence
The displayed text needs to have the CFE_LINK and CFE_LINKPROTECTED styles, along with explicit color and formatting styles. You then set the URL using the ITextRange2::SetURL method.
The MSDN blog post RichEdit Friendly Name Hyperlinks has a more detailed description of how to use them.
I just encountered the same problem recently and I just found that it's a bug of Richedit library. When I updated it from v4.1 to v5.0 the underline could be removed with no issues
Try sending an EM_AUTOURLDETECT message to the RichEdit control with wParam=0, lParam=0
"Specify 0 to disable automatic link detection...": https://msdn.microsoft.com/en-us/library/windows/desktop/bb787991(v=vs.85).aspx

How can I clear the focus from a desensitized GtkWidget - GtkSpinButton with property sensitive = false

Background: I have a few tabs set up in my GtkNotebook, and when certain conditions are met on the main tab, then input fields in the 'test signals' tab are accordingly disabled.
When the input inside a GtkSpinButton is highlighted on the 'test signals' tab and the GtkSpinButton's property sensitive is set to false, the text within the GtkSpinButton remains highlighted. Because sometimes there are no other editable fields on this tab, the text remains highlighted until another widget has its property sensitive set to true.
This just looks sloppy to me, so I would like to stop this behavior and have the widgets that are set to sensitive = false all cleared of focus or highlighting. Any idea how to un-highlight the text within the GtkSpinButton, maybe before setting sensitive = false?
To get rid of a selection you can use the gtk_editable_select_region() function. This is a method on GtkEditable, an interface that both GtkEntry and GtkSpinButton satisfy. You can convert either of these to GtkEditable with GTK_EDITABLE(). For example:
gtk_editable_select_region(GTK_EDITABLE(spinbutton), 0, 0);

Qt - Set display text of non-editable QComboBox

I would like to set the text of a QComboBox to some custom text (that is not in the QComboBox's list), without adding this text as an item of the QComboBox.
This behaviour is achievable on an editable QComboBox with QComboBox::setEditText(const QString & text).
On a non-editable QComboBox, however, this function does nothing.
Is it possible to programmatically set the display/edit text of a non-editable QComboBox to something that is not in its list?
Or do I have to find another way (e.g. use a QPushButton with a popup menu)
EDIT: Consider an editable QComboBox with InsertPolicy QComboBox::NoInsert. If the user types in something and hits enter, the entered value will be used but not added to the list. What I want is this behaviour to change the 'current' text programmatically, but without allowing the user to type in some text himself. The user can choose something from the QComboBox, but some time later, I may want to override the 'current' text.
I had the same problem when I subclassed QComboBox to make a combo box of check boxes. I wrote a small function to programmatically change the text displayed in the combo box, but I didn't want to enable the user to edit that text. The solution was to set the combo box as editable:
this->setEditable(true);
and the QComboBox::lineEdit() to read only. Refer to the function:
void CheckedComboBox::setText(QString text)
{
QLineEdit *displayedText = this->lineEdit();
displayedText->setText(text);
displayedText->setReadOnly(true);
}
Reimplement paintEvent : https://github.com/qt/qtbase/blob/28d1d19a526148845107b631612520a3524b402b/src/widgets/widgets/qcombobox.cpp#L2995
and add this line : opt.currentText = QString(tr("My Custom Text"));
Example :
QCustomCheckComboBoxFilter.h
...
protected:
void paintEvent(QPaintEvent *e) Q_DECL_OVERRIDE;
...
QCustomCheckComboBoxFilter.cpp
...
void QCustomCheckComboBoxFilter::paintEvent(QPaintEvent *)
{
QStylePainter painter(this);
painter.setPen(palette().color(QPalette::Text));
// draw the combobox frame, focusrect and selected etc.
QStyleOptionComboBox opt;
initStyleOption(&opt);
opt.currentText = QString(tr("My Custom Text"));
painter.drawComplexControl(QStyle::CC_ComboBox, opt);
// draw the icon and text
painter.drawControl(QStyle::CE_ComboBoxLabel, opt);
}
...
I supposed that you want to have a combo box with "A", "B", "C" as actual data and "This is A"
, "This is B" and "This is c" as what is displayed in QComboBox. Here is the code:
box.addItems(QStringList () << "This is A"<< "This is B"<< "This is C");
box.setItemData(0, "A");
box.setItemData(1, "B");
box.setItemData(2, "C");
You can get the actual data with this code :
QString actual = box.itemData(0).toString();//actual will be = "A";
qDebug()<<actual;//"A"
Note: You can almost set every data types that you want for a combo box Item. Even more, you can set more that just one additional data for each item with the third parameter of setItemData.
I ended up using a QPushButton with a popup menu.
I added the items I had in the list of my QComboBox as QActions to the menu.
A menu can be set on a QPushButton with
QPushButton::setMenu(QMenu* menu)
.
The text on the button can easily be set with
QPushButton::setText(const QString &)
and is unrelated to the text in the popup menu, which is what I wanted.