Code to select the PushButton using Tab Key - qt

I have designed the UI screen which consist a lot of push-buttons and I want to select or can say want to control application using tab key. When I select any particular key, it should change the color of that push-button accordingly.

As far as I know, the focus on using the tab key should work by default and the color of the buttons changes according to focus.
I tried to create a project with several buttons on QMainWIndow and it worked without any additional effort. I'm using Qt 5.15 with KDE on arch linux.
If you want to change the order of the buttons traversal, you can use the button that changes the designer mode in Qt Creator.
And if you want to change colors of the button, you should change the stylesheet of the button with css like code. Here you can see examples of stylesheet customization.

Related

Show a QT UI in another one

I have a project including 3 UI files: win_main.ui, win_table.ui and win_table2.ui.
I want to show one of them inside of win_main.ui, and with a button, change them.
I mean, there is a Box containing win_table.ui, and when I clicked the button, the box will change to win_table2.ui.
Example
I tried using QWidget, QQuickWidget, but they didn't worked.
Is it possible ? If yes, how ?
Try using a QTabWidget. You can flip between tables using tabs.
If there is a specific reason why you wouldn't want win_table2.ui showing before a button is pressed, you can disable that tab programmatically until it is ready. You can also flip between which tab is currently showing using code as well.

Qt creator - make a dynamic interface

I am working on a small UI with QT Creator and its drag-n'-drop tool (QT Designer). Everything was fine till I realized I had to make some widgets dynamic. For example, I have a checkbox and I want some button to appear only if this checkbox is checked by the user or I would like to change the appearance of another widget when the user clicks on some button.
Is it possible to do it only with QT Designer?
Yes, but it's very limited.
Qt designer have signal&slot editor. Yes, you can connect signal clicked(bool) to setVisible(bool) slot on button and make button visible only when checkbox is checked (see screenshot).
But when You need more complex dynamic interface (e.g. creating buttons), designed will not help You.

Does Qt have combo boxes like Word?

In Microsoft Word, if you want to use Bullets you have a combo box (If we can call it a combo box) to select the shape of the bullet (by clicking the little triangle) or you can just apply the default one by clicking the combo box's button.
Actually the combo box in Word has two parts. For an example let's consider a situation where I want to have a combo box in Qt that has these items as menu items:
"Restart", "Shutdown" and "Log off". User needs to choose one of them but he also can apply previously selected item by clicking its button exactly like Windows shutdown menu in start. You can click Shut down or select another option.
How can we achieve this in Qt?
If you are pursuing after a menu that looks like in the second picture, you can use QToolButton to achieve your goal. Use a QToolButton with popupMode set to MenuButtonPopup. It will render a control something similar to following.
Then you can style the look & feel further more using Qt Style Sheets. Read this example on how to style a QToolButton.
Create a QMenu dynamically, so you can attach it to the QToolButton at run-time in such a way that all items will be included in the menu except for the default item. Default action has to be assigned to the QToolButton itself.
You can use void QToolButton::setMenu (QMenu * menu) to assign a QMenu to your QToolButton at run-time.
If you are trying to design a control that is in your 1st screenshot, you will have to create a custom Qt control I guess. There is no default control available, which can yield that look & feel out of the box.

How to correctly set the color of a QPushButton?

I can successfully change the color of a QPushButton using setStyleSheet, but because I'm using QT Creator to make the GUI, every time I run qmake and make, the calls to setStyleSheet disappear.
Changing the palette of the button doesn't change its color either.
What's the best way to change to color of the button without having to manually change my ui_window.h file every time I qmake?
Using style sheets is the right way to do, no matter you're using Qt Creator or not.
From what you are describing, it seems you are writing yourself some code into the ui_window.h, which is the wrong way to set the stylesheet.
You can set it in the constructor of your window class, or set it from the GUI editor (Qt Designer) :
double-click on your window.ui in the project tree displayed by Qt Creator.
select your QPushButton in the GUI editor.
locate the styleSheet property in the properties editor.
click on the three dots (...) : this will bring a stylesheet editor.
If you set the stylesheet with the stylesheet editor, nothing will disappear each time you are rebuilding your app.

Qt QComboBox popup position

I'm working on an application which contains an editable QComboBox. I observe the following behavior when I enter some text in the edit field and press the dropdown arrow in the combobox:
My edit line ends up hidden behind the item "e#abc.com". I would like to have the combobox list popup below the edit field, like in the below screen:
The first screen above is taken on Ubuntu with Qt 4.5 while the second screen is from Suse 11 with Qt 4.4. I'm not aware of any differences regarding change of behavior of QComboBox popups between Qt 4.4 and Qt 4.5. Regardless, I would like the list to behave the same in both distributions.
This is a standard QComboBox with the editable property set to on - there are no stylesheets or special formatting applied to it.
How can I make the list popup below the editable field, like in the second screen?
This looks like a style issue, as the screenshots are taken with different styles. Perhaps you can start investigating by changing style on the failing desktop.

Resources