Items or widgets? QGraphicsItem or QWidget? Which should I choose? Can you do everything with both? Mostly. You can write a games board widget, or a games board scene. An audio spectrum widget, or an audio spectrum item. Is QWidget faster? It can be, especially for simple widgets, and if you do everything right and have the time to spend. Will Graphics View save me time?
Maybe the task you're trying to solve is a perfect match for Graphics View, and as you go along implementing it, you implement zooming and scrolling and right there I'd like to double-click to open a line edit - pushbutton box but... how? Maybe you search the QGraphicsItem docs and can't find anything, so you create a QPushButton, and uh.. Where do I put it? Who is its parent? What do I do when the user scrolls the view? (Install event filters?)
void MyItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
QPushButton *button = new QPushButton("Hello!", event->widget());
button->move("#¤!¤ &am!#¤!"#¤%&/(/p;!¤#QRE // censored
Embedding a widget inside a QGraphicsScene... does stir your interest? Have you ever invested time and energy on creating the world's finest widget, and then wanted to use it with Graphics View? Or maybe your scene could use a combobox /right there/, but then you go... oh, I don't have any QGraphicsComboBoxItem. So what do you do?
With either approach, what you want is to end up with something like this, graphics items and widgets dancing together as if nothing had happened:
I myself and several other Trolls've spent some time researching this topic. It's not trivial; most solutions to embedding widgets into a scene end up with several serious drawbacks. That's also why Qt doesn't have any off-the-shelf solution to this.
So, fundamentally, the two are very different. But place some push button items on a scene, and pull up a view, and compare that to QPushButtons inside a QScrollArea, the two look the same, and feel the same. But they aren't the same. And that especially comes into play when you try to combine them.
I think the most reasonable thing to do is to either use the widget directly, or write your own custom control. To demonstrate the first approach, I've added a Graphics View experimental items section in Labs. You can take a look, download the example and see how it works. This approach doesn't support transformations, but... when was the last time you typed text comfortably into a line edit at a 22 degree angle?...
Btw, later on we'll be adding more experimental items to this page. If you have suggestions, please let us know.
Stay up to date with the latest marketing, sales and service tips and news.
Download the latest release here: www.qt.io/download.
Qt 5.12 was developed with a strong focus on quality and is a long-term-supported (LTS) release that will be supported for 3 years.
Näytä tämä julkaisu Instagramissa.
Want to build something for tomorrow, join #QtPeople today! We have loads of cool jobs you don’t want to miss! http://qt.io/careers #builtwithQt #software #developers #coding #framework #tool #tooling #C++ #QML #engineers #sales #tech #technology #UI #UX #CX #Qt #Qtdev #global #openpositions #careers #job
Henkilön Qt (@theqtcompany) jakama julkaisu