Make a QDialog read only, but still with text selectable - c++

Disclaimer: I'm not a Qt programmer, I'm just asking in case someone could solve an issue about DB Browser for SQLite.
So, an EditDialog widget is extending the QDialog class. As described in the issue, in some scenarios this widget is readonly, but it would be great if its text content could still be selectable.
There are two use cases:
text selection with the mouse
blinking caret, text selection with keyboard Shift + arrows
The current solution fixes only the first case. There is no blinking caret and keyboard selection doesn't work. Could this be improved?

Assuming the textarea is a QTextEdit or QPlainTextEdit, you should be able to fix this by adjusting the text interaction flags. Try something like this:
ui->editorText->setTextInteractionFlags(
Qt.TextSelectableByMouse | Qt.TextSelectableByKeyboard)

Related

How to Change django-autocomplete-light input box styling?

I have gotten the autocomplete to work with my Database and my front end, but the input widget looks slightly off.
Is there a way to change the styling for the input?
Also, is there a way to remove the initial dropdown, so after you click once, you can start typing and suggestions will appear? I am using the ListSelect2 Widget. The Select2Multiple looks like more of what I need but I want input to be only one.
Current Widget Pre-Input
Current Widget During Input
Current Widget After Selection
Desired Look (Select2Multiple Widget)
I would appreciate any suggestions!

How can I put QTableWidgetItem into edit mode?

I am taking an existing UI component that we have based on QTableWidget and placing two of them inside QTabWidget pages. I want to allow the user to enter data into the table in the first tab and then when they press a button to move to the second tab and have the first cell in edit mode.
I am using the editItem method of QTableWidget to edit a given QTableWidgetItem. The trouble is that something is occurring to stop the edit (or maybe it never starts in the first place).
If I call editItem a second time then it fails, but if I click on the cell then it will enter the edit mode with the cell highlighted and the cursor blinking. I was just wondering if there is a way to do this programmatically that I may have missed?
One option would be to simulate a tab key press and then shift-tab but I have not been able to do this. I can simulate the tab but if I try to add the shift modifier then it jut produces a normal tab.
This is my tab code that works:
QApplication::postEvent(tableWidget, new QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier));
This is my shift-tab code that doesn't work:
QApplication::postEvent(tableWidget, new QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier));
Any suggestions would be appreciated.
It looks like shift-tab is actually reported as Qt::Key_Backtab rather than Qt::Key_Tab with the shift modifier as I had expected...
I think this will do the job for us but would welcome any better solutions.

Add some text to a QToolBar

I am having trouble adding some text in a QToolBar. I can only add Actions. Also I have two actions with their rerspectives icons in my QToolBar but I want to separate them and I canĀ“t either.
My newbie approach was to add empty actions to simulate blank spaces between the icons. But the user can click on the blank spaces.
I am using the Design function of QT Creator. Some help would be really apreciated.
It looks like you can't do it from within Designer:
https://bugreports.qt.io/browse/QTBUG-1267
That's an oooold suggestion, too, with a low priority to boot, so it probably won't get fixed any time soon.
You can get your hands dirty and do it in code, however.

Hide label text for Qt tabs without setting text to empty string

I need a QTabWidget with icons only:
How can I hide the label text of a tab in Qt? I cannot set the text to an empty string (""), as I am using docked widgets ( QDockWidget ) and the label text is set automatically (and I need it if the widget is floating).
But in tabbed mode I just want to display the icons (of the tabs).
Possible approaches:
Font size to 0?
I need to create my own bar class and override the paint event as here
Anything easier / cleaner?
--- Edit ---
Ok, the "set window title to empty string, and reset it the original text" approach works. I am using the topLevelChanged signal for this. However, it has some drawbacks, as the empty text still occupies some space. Another issue, with the text the tooltip is gone, and I cannot set it back.
What I am currently trying is something in-between the "text empty" and Prasad Silva's approach. I try to identify the text label inside the tab and set its size to 0, then reset it. It's slightly different, but would keep the text intact.
Btw, I see a line on top of my tabs, any idea what this is (where it comes from)?
Edit: There seems to be no "easy way" (style sheet, attribute) for this, see Hiding bottom line in QTabBar
Maybe I will create the whole tab bar on my own, as the automatically generated stuff is just too hard to handle (agree with PS on this).
This can not be done easily. Use empty text.
The way I solved something like was to create a QDockWidget subclass that installed a QWidget subclass as the titlebar (via setTitleBarWidget). This gave me control over showing/hiding the text in the titlebar when the dock widget fires topLevelChanged, dockLocationChanged and visiblityChanged.
This is really a big hack to get around the fact that Qt has refused to expose a public API for the docking system. We have since moved on to a custom docking implementation due to these limitations.
If you do not want to see the text, you can set it to an empty text after saving the current text, and when you want to see it again, restore it from the stored variable.
I do not think there is anything in the API for this not so common case, which means you will need to do it yourself.
Now, you could claim that it is tedious to do for many widgets, but on the other hand, you could write a simple hash define or inline function to do this repetitive work for you, which would only result a one-liner call, basically, which you would need to use anyway when changing the state.

Intput/Output to QLabel?

I would like my input from the keyboard to be sent to a QLabel. But I dont want just to put the text in it as label->setText("") but instead to see every letter from the keyboard to appear immediately in the label. Any ideas? I just need someone to point me in the right direction. Thank you in advance.
This is not directly possible. But you can create a class inheriting QLabel and reimplement keyPressEvent to handle this manually.
You can use a QLineEdit and make it read only and use stylesheets to hide borders etc...
Have a look at the stylesheet info here
Qt Stylesheets