Unsolved Settings widget into focus programmatically.
-
I have custom QComboBox with QTreeView that I would like to show when user press on the drop down arrow to show combo options.
I replaced QComboBox::showPopup call with me showing the tree in the correct place location.
I also set these parameters on the tree :
mView_tree->setFocusPolicy(Qt::StrongFocus); mView_tree->setFrameShape(QFrame::NoFrame); mView_tree->setWindowFlags(Qt::Tool | Qt::CustomizeWindowHint);
And I showPopup :
... some code mView_tree->move(loc); mView_tree->show(); mView_tree->setFocus(Qt::MouseFocusReason);
When the tree shows up, it does not have focus. How can I get it to focus properly?
I also tried this in case some QComboBox signals break stuff - at the bottom of showPopup func.
QMetaObject::invokeMethod(mView_tree, [=]() { mView_tree->setFocus(); }, Qt::QueuedConnection);
Sadly no luck, any info/help?
TIA
-
Hi
But who has focus then?
Try use
QApplication::focusWidget()
to see what widget steals your focus. -
Thats a brilliant thing!
Its the evil combo box ! -.-
What can I do to drop its focus? I'm lost :- (
-
@Dariusz
The first test might be to
combo->setFocusPolicy(Qt::NoFocus); -
@mrjj said in Settings widget into focus programmatically.:
combo->setFocusPolicy(Qt::NoFocus);
Nope still in focus :- (
-
Hi,
How are you creating that special QComboBox ?
-
@SGaist
Hey
Goes pretty much like this now that I look at it :
combo is placed inside QWidget that is being used as asetTitleBarWidget(menuBarWidget);
#include "QComboBox" #include "QTreeView" class comboExample :public QComboBox{ Q_OBJECT QTreeView *view; public: comboExample(); ~comboExample(); void showPopup(); void setModel(QAbstractItemModel*model); };
#include "comboExample.h" #include "QHeaderView" comboExample::comboExample() { view = new QTreeView(); view->show(); view->setStyleSheet("border: 1px solid gray"); view->header()->setHidden(true); view->setFrameShape(QFrame::NoFrame); view->setEditTriggers(QTreeView::NoEditTriggers); view->setAlternatingRowColors(true); view->setSelectionBehavior(QTreeView::SelectRows); view->setWordWrap(true); view->setAllColumnsShowFocus(true); view->setWindowFlags(Qt::Tool | Qt::CustomizeWindowHint); setMaximumWidth(100); setAttribute(Qt::WA_TranslucentBackground, true); setMaximumHeight(22); } comboExample::~comboExample() { } void comboExample::showPopup() { //QComboBox::showPopup(); view->move(pos());///wrong pos ... view->show(); view->setFocus(Qt::MouseFocusReason); } void comboExample::setModel(QAbstractItemModel *model) { view->setModel(model); }
-
This Wiki article shows a starting point to get a tree view inside a QComboBox. It needs some cleanup but should get you started.
-
That article answers quite a few questions I had about that scenario, woah nice thanks!
But... I kinda like the idea of more "control"... somehow, creating the widget this way allow the user to resize it which won't be possible using a popup, so I would like to get the focus to work properly...
TIA