For example we have a groupbox with some amount of lineEdits.
When user press Tab focus from one lineEdit changed to other.
How to make focus change in the specific order?
In my Dialog focus changed in a very strange way. For example cursor jumps this way 1 3 2 4 lineEdits. I want to make it jumping 1 2 3 4 lineEdits
I think that the order is such because I added this line edits in such order...but remaking all GUI is not a solution for me...
In a designer you should select Edit->Edit Tab Order (blue numbers will appear).
Than you click on your widgets in the order you want them (numbers will change).
After you are done, you should select Edit->Edit Widgets (or press F3).
If you are not using designer, use:
void QWidget::setTabOrder ( QWidget *first, QWidget *second );
Qt Designer: Edit->Edit Tab Order
Related
Qt's QMainWindow has a ability to dock windows derived from QDockWidget. It also would put one on top on the other if few of them are stacked, producing a tab bar. Whenever a QDockWidget's state changes a signal topLevelChanged() is emmitted. At this point I would like to get access to underlying QTabWidget to set an icon for a a newly added tab. How can I do it? My patience is over trying to dig the answer out from Qt's documentation and source code. Thank you in advance.
So icon I want to be on Contents/Index tabs.
Once at least one dockwidget has been tabified, the main-window will create a QTabBar to provide the dock-tabs. Each dock-area can have its own tab-bar. These tab-bars will become children of the main-window, so you can use findChildren() or children() to get references to them.
The main difficulty will be in finding which dock-widget belongs to which tab and in which tab-bar. If the dock-widget window-titles are all unique, you can just search using the tabText(). Otherwise, you might be able to use the tabData(), which Qt sets internally to a quintptr from the dock-widget.
Once you have the correct tab, you can of course use setTabIcon() to add your icon. But note that every time a dock-widget is untabified or moved to another tab-bar, the icon will be lost.
I want to implement my own sequence for changing the focus of the active child widget using the Tab key. How to capture the Tab Key press event? I am using Qt5.2
If you want to change focus with Tab , you don't need to do those works, Qt has it as a feature.
First: set the desired widgets to be Qt::TabFocus or Qt::StrongFocus by QWidget::setFocusPolicy( Qt::FocusPolicy policy )
For example, if you want to rotate between 3 QLineEdit and 1 QCombobox, you have to assure that their focus policy have been set right. (Normally either Qt::TabFocus or Qt::StrongFocus will be set as default, but sometimes you might want to escape some widgets from being tabbed)
Second: go to designer mode and click "Edit Tab Order" to enter the tab-order editing mode
Third: After seeing the numbers, click on them until you got the desired sequence order.
(Picture from Qt official site)
Have a mouse press event or a event filter, get to the point where you have a QKeyEvent
Then only do something if tab was pressed
key_event->button() == Qt::Key_Tab
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.
I have a Combobox which has 3 items i.e. Item 1, Item 2 and item 3. I added these 3 items in .ui file and also added an image each for all using a resource file. Now when I am running the application, it shows the first item in combobox along with a image towards left. When i click on dropdown, I can see all the items along with images.
What I basically want to do is just display the image in the combobox and when user clicks on dropdown, it should show the image and text too.
Scenario: Items and images inside Combobox are added as follows:
Image 1 Item 1
Image 2 Item 2
Image 3 Item 3
When I run the app, it should display in combobox as
Image1
since first item gets displayed by default. I think it can be done when painting the current selection, QCombobox uses a re-implantation : void MyCombo::paintEvent(QPaintEvent *e) which is something I am not aware of.
Can anyone help me in this?? :)
How can I achieve it???
You hould inherit a QComboBox and reimplement void QComboBox::showPopup () [virtual]
P.S. If you reimplement this function to show a custom pop-up, make sure you call hidePopup() to reset the internal state.
Second idea I have is to implement a model for combobox but i don't now exatly is there any roule for popup elements.
I saw once someone making the GUI in QT and he had something I have never seen until now: They looked like big buttons one after another and when you clicked on them, the buttons below were going down, making space for the dialog or tab. It was like, if you click on the button "Draw", suddenly below the button a tab or a dialog or ??? appeared with all the GUI components (radio buttons, listboxes, ...) that you need for draw. When you clicked on another button, this GUI disappeared to make space for another GUI. Does anybody know what it is?
Qt does support tabs.
They are actually different widgets you can switch from in the same window.
Here you can find an example on how to use then: http://qt-project.org/doc/qt-4.8/declarative-ui-components-tabwidget.html
Inside a tab it's just like a normal widget.