I have a dialog box with 2 radio buttons. Each should be connected to a Q*BoxLayout (some content in it), so when the user presses first one, it should show the first Layout with its content, if the user chooses second one, it should display (or enable the visibility) of the second, but I cannot hide an entire layout
Is it possible to hide it?
If no, what would you suggest?
Put the content of the boxlayout inside a QWidget. Then add suitable boxlayout to the QWidget. Now you can hide and show that container widget.
Related
I want to build a widget like this one that we can find in Word :
So, there is a list view using a specific scrollbar with 3 buttons and no scroll.
When you click on the last button at the bottom right, a new list view with a classic scrollbar is shown over the previous list view (hidden when losing focus). So basically, the smae behavior as the one in Word.
We are already capable of displaying a list view with custom content.
My main concern is how to build the widget in the first image: the list view with the custom scrollbar (3 buttons, no scroll)?
What is the proper way to do this ?
I assume that you're implementing a subclass of QAbstractListView.
I don't believe you need a custom scrollbar - just put the scrollbar and the button into a QVBoxLayout; hide the button once it's checked (you could even connect its toggled() to its setHidden() for that).
At first hide the default scroll-bar by calling the QAbstractScrollArea::setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff) method.
Then create your three buttons on the left side and connect the QPushButton::clicked() signals to some slots where you just scroll your list by calling the QAbstractItemView::scrollTo(index), QAbstractItemView::scrollToBottom() or QAbstractItemView::scrollToTop().
While it is correct that you could just build a custom widget consisting of a view with hidden scrollbars and add the buttons to the layout, connecting the signals/slots needed to provide the proper actions, you can also consider to implement your own QScrollBar class. QListView is derived from QAbstractScrollArea, which provides setVerticalScrollBar() so you can just set an object of it to be used by the view. The integration of scroll area and scroll bar should be much more straightforward this way, but you'll have to do the painting of the scroll bar's content yourself, or put a layout and the buttons in there (QScrollBar derives from QWidget, and you'll have to reimplement paintEvent()).
I have designed a form in QtCreator for Qt5 where I have a row of buttons without layout (Blueberry+, Peach, Lemon, Mango and Water in screenshot below) with a grid layout on top.
The grid layout has one button (Register Now), one label(HELLO JOHN) and two horizontal spacers inside:
In the code, the label and button in the layout are set to visible=false.
When I start the program and show the screen I only see the underlying row of buttons, but I can't click them. The layout seems to somehow steal the focus. I can verify this by moving the layout in the editor to see the boundary for where my clicks work following it.
Other than this there isn't much going on in the gui, so I am kind of stumped as to why a QGridLayout steals my clicks.
Any tips on how I can avoid this?
You should hide the QGridLayout itself and not the button and label.
You are done here if the button and label hides and shows togather.
if not. along with showing and hidding the grid. show and hide the label and button.
Does that seems to solve the problem?
Is it possible to add some widgets to a QTabBar? I wanted to have a QComboBox to the side of the last tab, and have it only appear when the last tab is selected.
It's possible to add child overlay widgets to any widget, so the answer is: sure!
You can hook to the tab widgets's or tab bar's signals to get notified when the last tab is selected. Then use tabRect() to get the rectangle of the last tab. Position your combo box to the right of it. It'd need to be a child of the tab bar. That's it.
It might be easier to use a QStackedWidget to get your desired results. When you are using the QStackedWidget you can have different buttons outside that reveal the different widgets. Then use some custom signal for when the last button is activated to show a combobox that appears next to the last button.
Here is the link to the QStackedWidget
I have a form written with Qt Designer, which contains a QWidget promoted to a custom widget I have. The custom widget contains several combo boxes. I want the form to have a reasonable tab order, with focus moving from the widget immediately before the custom widget, then going through the combo boxes in the custom widget, and proceeding to the widget after the custom widget. So I set the QWidget to have tab focus in Designer, but the custom widget doesn't handle having focus properly.
I could solve this problem using QWidget::setTabOrder, but that would be messy because I would have to reach into the custom widget from the outside. Alternatively I could give the custom widget a member function to set the tab order. Ideally there should be a simpler way. Is there?
I've got an app that uses several CView-derived classes (actually CScrollView) to display document data. For one particular view, I want to add a fly-out edit box to add notes. That is, you'd see a tab at the bottom of the window labeled "Page Notes", and clicking on that would bring up the edit box. Clicking the tab while the edit box is visible would reduce it back to just the tab.
I thought I could use a one-tab CTabCtrl holding an edit box and just position it so that only the tab is visible initially. Capture the tab click notification and move the entire control, with edit box, into view. Clicking the tab again would move it back down so only the tab is visible.
Hosting the CTabCtrl on the CView is fine, and I can get it positioned correctly. The problem is that if the view is scrolled, the tab control is scrolled along with it, whereas I need it to "float" over the view and not be affected by any scrolling. I can move it back into place after the scroll, but the flickering is unsightly.
Is there a straightforward way to accomplish the "floating" effect? I mainly want the tab embedded in the view for maintenance, since it's the only view class out of the several in use that needs the "Page Notes" feature.
Should I just buckle down and put the tab in the view's parent window instead? I know it won't be affected by scrolling there, but I like the idea of keeping the tab as part of the view if possible.
It sound like the tab is functioning like a button. You click the tab and a fly out edit box appears. You could use a modeless dialog.
Select the "Page Note" and the modeless dialog comes up to edit your notes allowing you to scroll your view under the dialog.