Sidepanel with Qt - qt

I'd like to implement a sidepanel in my Qt window. I search something like the one that is used in the Visual Studio (see below).
Important notes:
The widgets don't have to be moveable
resizing should be possible
each widget should be clearly separated from the other layout
Does anyone have an idea how I could build such a sidepanel? (Maybe there even exists a library)
Or does anyone know a project which uses Qt and some kind of sidepanel?

One option would be to use QDockWidgets. That's the type of thing they are intended for inside a QMainWindow.
You can put toolbars, QTreeViews and QTableViews (or related) widgets inside your dock widget to simulate the screenshot you posted.
For an example usage: Dock Widgets Example.

Related

Layout required in designer but not in hand coded app?

I'm new to Qt and it's quite a learning curve!
I've been search/reading/hacking and learning for most of the day on this one.
I'm working on an app that will have a image in a scroll area as it's main purpose. The image viewer example is where I started. This example appears to be "laid out by hand" if you will - i.e. there are no .ui form files for it (it's trivial so why not).
So here is the rub - I want to use designer to build a much more sophisticated app. If I start fresh with a new project and use designer the resizing doesn't work unless I add layout (used vertical, all appear to fix the resize issue) to the .ui form.
Designer creates a lot more code to do the same thing - I don't care, it is after all an IDE / code generation tool.
However it's not clear to me why the layout is required when I use designer and not if I code it by hand. I searched the code for the image viewer example and there doesn't seem to be ANY layout involved at all, just 3 or 4 nested widgits (Main/Scroll/Label).
Is the default layout basically built in?
The example you linked to uses a QMainWindow. This widget has its own layout because it has built-in support for menubars, toolbars, dock widgets and a statusbar:
Main Window Framework:
Normally, the widget set as the central-widget would need to have a layout explicitly set on it in order to layout its own child widgets. However, in your linked example, the central-widget is a QScrollArea, which also happens to have a built-in layout. This is all just coincidental, though. The large majority of widgets don't have a built-in layout, so most GUIs will need to explictly add at least one layout, and several will usually be needed for more complex applications.
I would say Qt Designer is absolutely essential when it comes to experimenting with layouts (especially when you start learning Qt). Even if you don't actually use the ui file, it's still very helpful to just view the code that would be generated from it.

How can I create a system similar to QDockWidget but for tabs?

I had an idea I have no clue on how to implement. I'm working with Qt and I'ld like to have a system of tabs that allows me to use tabs in the same way one can use QDockWidgets, that is: with QDockWidgets one can pick a widget and use it floating around the monitor or he can dock it in a QMainWindow in any of the four sides. Well I would like to have such attribute with a QTabWidget! So suppose I have two QTabWidgets in front of me. With the proposed idea, I would be capable to drag and drop a tab (with its widget) from one QTabWidget to another or even simply undock it from its original QTabWidget and start using it independently as another QTabWidget with one tab.
Well I couldn't find a way to use QTabWidget this way "naturally"; it seems Qt doesn't provide such possibility with its pack of widget classes. So does anybody knows any project open to the public containing a class able to do such thing? Or how could I implement such a new class myself? (I don't know for example how could I make the drag and drop effect from a QTabBar since even if setMovable is set to true, still isn't possible to make the tab go away from area of the QTabBar.
Any help will be appreciated.
QDockWidgets already provide possibility to be tabbed.
You can check Dock Widgets Qt sample project in Main Windows section.
Screen of the just launched sample app:
Screen of the tabbed doc widgets:
Check this answer for implementation details.

Which widget is used in Visual Studio's central widget?

I want to use Qt to build a GUI with a central widget like the visual studio. The widget has a number of tabbed windows to edit h/cpp files. Which widget should I use?
You can create only something similar to Visual Studio using Qt classes. Central widget should also have layout. Only QMainWindow has setCentralWidget method.
QTextEdit with QSyntaxHighlighter to make your text with color.
QMenu requires also QAction. You can also use QToolBar
QSplitter allows you to move(resize widgets)
QLineEdit for small texts (for example search word or something else)
Description:
I think the closest thing you can find to replicate the visual studio tabbed windows is QMdiArea. But if you want the full functionality of Visual Studio's tabbed widgets you need to implement your own widget.
I run into the same problem and found a library that adds the ability to use similar layouts as VS do: dynamically resizable, stackable (horizontally, vertically, on each other), undockable, closable, saveable.
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System
It has its own issues (at least on Linux), but it's a good point to start, anyway.

Qt drawing with Qt designer

I have tried to search on the internet and here as well, without success though. I am using Qt 4.8.2 and design my app in the Designer, then I write code in VS2010. I would like to show a chart on the application window, e.g. like http://www.infocaptor.com/user_help/help_img/dashboard_line_chart_screen.png , based on some data that are created by the app.
In the Widget Box of the Designer, I can't find any widget related to drawing. So I tried creating a QTextEdit and drawing on that using QPainter. However, this does not work. I can draw on the whole appwindow, but not just on the text edit. So the question is: what widget can be added onto the app window in the designer and that is going to allow me to draw on it using QPainter?
I'm eluded as the documentation says specifically that QPainter can draw on any QWidget which a QTextEdit is...
Any help is much appreciated,
Daniel
The function of "drawing" is tooo complex/unspecific to be included as a specialized widget. You'll have to create it yourself and implement the desired drawing functions.
Here is an example which you can learn from, the scribblearea class could be pretty much what you are looking for. In that case you can copy it to your project and use in in the Qt-Designer by promoting a widget to this class.

Disabled splitter in qt designer

I'm using qt 4.8.0 on windows 7.
When I open qt designer and create widget in it, I cannot set 'Lay Out in a vertical/horizontal in Splitter'. Also there is no Splitter in a Layouts widget box.
All other layouts are working well.
Have anyone run into same or similar problem?
You need to select two or more widgets and then use the layout -> vertical/horizontal splitter option. This will give designer enough context to be able to perform the operation.
Also note that the selected widgets cannot be part of a layout already. If they are, you need to break the layout first (layout->Break Layout in context menu).
It's in the contextual menu that appears on right-click in the body of the widget.
You can establish the widget's layout including splitter there.
EDIT: Sorry, I misunderstood in a rapid first-reading. Are you saying it doesn't appear in the right-click menu, between the other layout options?

Resources