Intput/Output to QLabel? - c++

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

Related

Set QTabWidget Order by text of tabs

I am trying to set tab order by tab text or tab name
ui.tabWidget->setTabOrder(//set order here by tab name like "helloTab","hiTab");
//I have tried this(I know it's dumb just trying)
ui.tabWidget->setTabOrder(ui.tabWidget->tabBar->findChild<QTab *>("tab_1"), ui.tabWidget->tabBar->findChild<QTab *>("tab_2"));
Till now no hope of getting this done. I am fairly new to qt.
Any Ideas or help would be helpful.
QTab is not defined in Qt. Use QWidget:
ui.tabWidget->setTabOrder(ui.tabWidget->tabBar->findChild<QWidget *>("tab_1"), ui.tabWidget->tabBar->findChild<QWidget *>("tab_2"));

Make a QDialog read only, but still with text selectable

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)

Qt C++ - displaying the links in QText Browser

Right now I am displaying the result in QTextBrowser. Results will be something like /home/User/, /media/Arena/ etc i.e path to different folders. Now I want to open the folder in a window by clicking on this result which is displayed in QTextBrowser. But I have no ideas how to do that. So can anyone let me know how to do it.
Thanx in advance.
P.S. I am using QtCreator & see the image http://i53.tinypic.com/qyxp1s.png.
can you insert html rather than plain text into the QTextBrowser widget? then you can use a URL to describe the paths.
BasementCat's right. You can use setHtml QTextBrowser's method to set HTML into the widget. You'll then probably need to call setOpenLinks(false) to disable default behavior and connect custom slot to widget's anchorClicked(QUrl const&) signal to handle links.

Qt::How to lower the text in a QSpinBox

I'm using a spinbox with a custom font which looks too high in the spinbox. How do I move the text lower?
I have already reimplemented QStyle and made the font lower in another widget but I can't find where to do it with the spinbox. There must be a QRect somewhere where you can just move the top of it but I don't know and can't seem to find where it is.
Qt specifies a QStyle::SC_SpinBoxEditField, which appears to be what you want to modify. If I recall correctly from a few years ago when I was doing stuff with styles, you should be able to hook into getting options for that subcontrol, which would include the rect within which it is supposed to be drawn. Modifying that might get the result you want. If not, it is a place to begin searching for your answer.
This is more of a guess than a positive answer, but you might be able to do this with stylesheets:
spinbox->setStyleSheet("QSpinBox { bottom: -2px;}");
Ideally there would be a subcontrol or something for just the text, but the stylesheet documentation doesn't list one, which might imply the above will have undesirable consequences.
You can do:
spinBox->setAlignment(Qt::AlignCenter);//Or the Align Flag that you want
I hope this help.

Qt: How to show icon when item selected

I have a QListWidget containing items which have icons and when the items are selected the icon is just highlighted out. Is there a way to prevent this? I can't use stylesheets because it's for an embedded application and including them takes up too much space.
thanks
I suppose when you say "Highlithed out", you mean that the icon colors don't render well when the line is selected, and therefore, you can't see properly the icon...
Maybe you could consider using a different icon when the item is selected. It's possible to do so by specifing a mode to your icon.
Example :
QIcon MyIcon(":/images/foo");
MyIcon.addFile(":/images/bar", QSize(...), QIcon::Selected);
You can easily make a try in QtDesigner and see the results...
Hope it helps a bit !
Certainly, drawing on a black-and-white screen presents its challenges.
It sounds like you just want to change the appearance of the interface, not any functionality. If this is the case, a QItemDelegate-derived class (or QStyledItemDelegate) is almost certainly what you want. In particular, the drawDecoration function looks like it is used to draw an icon, and the style options should include whether it is selected. The simplest fix would be to override that function, set the selected flag in the options to false, then pass it up to the parent's function.