Solved Panels for toolbars?
-
Hi Forum.
I tried Qt a while back, but ended up using Lazarus and Free Pascal. That said, my first question here is this:
What design component do I use to build my toolbar on? In the other environment, I used panels extensively, and they were especially good for this. But I see no panels in the Qt toolset.
Thanks in advance for your help.
-
Hi and welcome to the forums.
What is does a panel do in the other frameworks ?
The QToolbar accept widgets via
https://doc.qt.io/qt-5/qtoolbar.html#addWidget
so you can most insert components in QToolbar.
and you can have multiple toolbars.
void QMainWindow::insertToolBar(QToolBar *before, QToolBar *toolbar)
Given sort of the features, we know from bands in other frameworks.
However, its unclear what you need from it so its hard to say which way to go :) -
@mrjj - I can set a panel and align it to the top of the form, set it's height to, let's say 100, and add icons, combo boxes, radio buttons, etc to it. I found a widget component in the Qt toolset, so many that's what I need here. I'll just experiment around.
Thank you for your response, mrjj. Much appreciated.
-
@Driftwood
Hi
Most widgets can be a container so you can use any widget to hold other widgets.
However, QFrame might be very suited for such panel.Please note that layouts are a bit different in Qt than in say VCL.
You put widgets in layouts that control the placement and size.
So if you look at the properties and wonder where the layout options is hidden, it's due to the fact that it works slightly differently.Also, just to be upfront. When you want to apply a layout to a widget,
you then right click and select one from the layout menu.
The red layouts shown in the widget list, is for inserting into other layouts but
is not good as base layout as they dont snap to the container but float around.
So right click:) for a base / top layout. -
@mrjj
Thanks for the heads up. The layouts will be different, for sure. Lazarus uses an excellent anchor system. In truth, it's the best I've ever seen for Form layouts. But I can adapt to Qt's system =) -
@Driftwood
I used Delphi/c++ builder for many years and yes the anchor is excellent.
That said, when you get to know the layout system, its also good to work with.
Last note you should be aware f.
When using designer, the UI files are used to generate c++ code.
If you look in the setupUI function you can see it.
That makes it possible to draw a complex layout and then steal the code to reuse
runtime/non visually.
So its not - use UI files or code. its quite possible to use both in a lovely mix. -
@mrjj
Thanks for the tip. I only hope you're as good with databases, because that's why I program. In truth, I'm working on an extremely complex database program now that's grid intensive, grids that contain combo boxes and checkboxes and all the fun stuff =) I'm sure I'll have a slew of questions for the forum when I begin this project using Qt. I've noticed Qt isn't as database friendly as Delphi and Lazarus, so I'm sure this will be a challenge for me.Thanks again for the layout tip.
-
@Driftwood
Oh. well Qt do not have database aware widgets in same manner as Delphi
but luckily Qt is very flexible and easy to extend.The way to have combo/checkboxes and the like in the data grid is to use
delegates which basically just draw the button/checkbox/xx when not in edit mode.
This helps to have good performance when many rows.https://doc.qt.io/qt-5/qtwidgets-itemviews-stardelegate-example.html
This example has a rating widget in the grid. Its excactly same way for any other
widget you want to include in a grids. (view)So its a bit work up front but the reward is max speed later :)
-
@mrjj
I may be switching over to Qt sooner than later. While I haven't done much with it, I know Qt is rock solid. And right now, I'm struggling with glitchy DBGrids. I'm fighting one right now that I have row selection turned off and it stays on. I just want to highlight one cell at a time, not twenty =)Yes, I believe Qt's the ticket, my answer to peaceful sleep, the DBGrid nightmares forever banished! =)
Thanks for the link.
-
@Driftwood
Hehe well after the initial work where you make your own DDGrid,
i think you be pretty happy.
Be aware that Qt uses models for most data viewing so for the first test, you should look at https://doc.qt.io/qt-5/sql-model.html
And for sorting and filtering, you use https://doc.qt.io/qt-5/qsortfilterproxymodel.html
While it taks a bit more initial setup, its also very powerfull and using a subclass you
can make it sort or filter in any way, you dream of, should the regular expressions not be
enough. -
@mrjj
WOW! That's awesome stuff! I wish I'd started using Qt a few years back; I'd be so far ahead of the curve by now. But there's no time like the present. You're a good salesman. Hahaha =) -
@Driftwood
Heheh good to hear.
That said, i still miss the WITH from Delphi/pascal in c++ :) -
I use with all the time. I'm sort of new to C++ and wasn't yet aware I cldn't do things like:
with DBComboBox_InventoryUnit do begin DataField := 'inventory_unit'; DataSource := DS_AddItems; Visible:= False; end;
But programming's programming. I'm sure it'll all bear the same fruit, just have to be gardened differently =)
-
@Driftwood
excactly :)
Nothing really comes close in c++ outside of ugly macro hax.you can do
auto & inv = *DBComboBox_InventoryUnit;
inv.DataFIeld = ".."but it really is not as elegant.
But on the bright side. c++ will offer many nice features not found in pascal if using
c++11 or more.