PDA

View Full Version : What is the best way to subclass and replace widgets from gui?



franki
21st May 2012, 12:53
Hi

Sometimes, or quite often, I need some extra functionality from items like QGraphicsView, QPushButton, etc, so I need to subclass them and add my functions, but this items are already in their places in gui because in QtDesigner I created them, I had do that because I want to know how interface will look like. So now, during application start I create my own object like "MyGraphicsView, public QGraphicsView", then I delete original QGraphicsView object created in ui_mainwindow.h and I place my object in the layout cell where the QtDesigner originally placed it. It work's for me, but frankly saying it's cumbersome and I'm not sure if it's right approach? Is there a better way to subclass items from gui? I know I could not to create this QGraphicsView in QtDesigner in the first place, but then working with gui interface in QtDesigner where there are blind spots instead of items is also cumbersome.

best regards
Marek

Zlatomir
21st May 2012, 13:08
You can promote (http://qt-project.org/doc/qt-4.8/designer-using-custom-widgets.html) widgets.