programmatically promote a widget
-
I would like to programmatically promote a widget. I don't have a ui form, so programatically is a must.
I would like to create a QScrollArea and promote it to a ScribbleArea. (so that the scribble area can be scrolled)
Is that in any way possible? -
Hi,
Why not just use the class directly ?
-
@SGaist What do you mean/how should I do that?
-
I tried to put the scribblearea into the scrollarea, but it didn't work. This is the code I tried:
MainWindow::MainWindow() { scribbleArea = new ScribbleArea; scrollArea = new QScrollArea; scrollArea->setWidget(scribbleArea); setCentralWidget(scribbleArea); createActions(); createMenus(); setWindowTitle(tr("Tekentool demo")); resize(500, 500); }
-
I tried to put the scribblearea into the scrollarea, but it didn't work. This is the code I tried:
MainWindow::MainWindow() { scribbleArea = new ScribbleArea; scrollArea = new QScrollArea; scrollArea->setWidget(scribbleArea); setCentralWidget(scribbleArea); createActions(); createMenus(); setWindowTitle(tr("Tekentool demo")); resize(500, 500); }
@hobbyProgrammer said in programmatically promote a widget:
setCentralWidget(scribbleArea);
I guess the central widget of your MainWindow object should be the QScrollArea...
... setCentralWidget(scrollArea); ...
-
I tried to put the scribblearea into the scrollarea, but it didn't work. This is the code I tried:
MainWindow::MainWindow() { scribbleArea = new ScribbleArea; scrollArea = new QScrollArea; scrollArea->setWidget(scribbleArea); setCentralWidget(scribbleArea); createActions(); createMenus(); setWindowTitle(tr("Tekentool demo")); resize(500, 500); }
@hobbyProgrammer said in programmatically promote a widget:
I tried to put the scribblearea into the scrollarea, but it didn't work. This is the code I tried:
MainWindow::MainWindow() { scribbleArea = new ScribbleArea; scrollArea = new QScrollArea; scrollArea->setWidget(scribbleArea); setCentralWidget(scribbleArea); createActions(); createMenus(); setWindowTitle(tr("Tekentool demo")); resize(500, 500); }
There's no need for scrollArea. Just use your custom widget.
The promote feature of Designer will modify the XML generated to use your custom class in place of the original. Basically replacing QScrollArea in the code by ScribbleArea.
-
Hi
Promotion by code would simply be to new the class you want.However, there is an one thing to consider with scribbleArea
There is no image size. The image is scaled to the size of the widget and if you
put it into a scrollArea, it would just take the size of the scrollArea.However, if you set a size to the Scribble Widget, and disable auto fit
then it can act as "image size"
and scrolling will work.Change Scribble mainwindow like this
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), scribbleArea(new ScribbleArea(this)) { //* new auto scrollArea = new QScrollArea(); scrollArea->setWidgetResizable(false); // dont scale to fit scrollarea scribbleArea->setMinimumSize(500, 500); // "image size" scrollArea->setWidget(scribbleArea); setCentralWidget(scrollArea); //* new // setCentralWidget(scribbleArea);
and it does allow scroll if "image size" is larger then the window.
-
Hi
Promotion by code would simply be to new the class you want.However, there is an one thing to consider with scribbleArea
There is no image size. The image is scaled to the size of the widget and if you
put it into a scrollArea, it would just take the size of the scrollArea.However, if you set a size to the Scribble Widget, and disable auto fit
then it can act as "image size"
and scrolling will work.Change Scribble mainwindow like this
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), scribbleArea(new ScribbleArea(this)) { //* new auto scrollArea = new QScrollArea(); scrollArea->setWidgetResizable(false); // dont scale to fit scrollarea scribbleArea->setMinimumSize(500, 500); // "image size" scrollArea->setWidget(scribbleArea); setCentralWidget(scrollArea); //* new // setCentralWidget(scribbleArea);
and it does allow scroll if "image size" is larger then the window.
This post is deleted! -
Hi
Promotion by code would simply be to new the class you want.However, there is an one thing to consider with scribbleArea
There is no image size. The image is scaled to the size of the widget and if you
put it into a scrollArea, it would just take the size of the scrollArea.However, if you set a size to the Scribble Widget, and disable auto fit
then it can act as "image size"
and scrolling will work.Change Scribble mainwindow like this
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), scribbleArea(new ScribbleArea(this)) { //* new auto scrollArea = new QScrollArea(); scrollArea->setWidgetResizable(false); // dont scale to fit scrollarea scribbleArea->setMinimumSize(500, 500); // "image size" scrollArea->setWidget(scribbleArea); setCentralWidget(scrollArea); //* new // setCentralWidget(scribbleArea);
and it does allow scroll if "image size" is larger then the window.
@mrjj
It doesn't seem to work properly. Whenever I draw something that fits the scribbleArea and then Zoom in, it still writes outside of the screen, but I would want to scroll to those area's too.after zooming in:
and this is how it looks when I don't size the app to my full screensize:
-
This post is deleted!
-
Hi
Promotion by code would simply be to new the class you want.However, there is an one thing to consider with scribbleArea
There is no image size. The image is scaled to the size of the widget and if you
put it into a scrollArea, it would just take the size of the scrollArea.However, if you set a size to the Scribble Widget, and disable auto fit
then it can act as "image size"
and scrolling will work.Change Scribble mainwindow like this
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), scribbleArea(new ScribbleArea(this)) { //* new auto scrollArea = new QScrollArea(); scrollArea->setWidgetResizable(false); // dont scale to fit scrollarea scribbleArea->setMinimumSize(500, 500); // "image size" scrollArea->setWidget(scribbleArea); setCentralWidget(scrollArea); //* new // setCentralWidget(scribbleArea);
and it does allow scroll if "image size" is larger then the window.
@mrjj said in programmatically promote a widget:
and it does allow scroll if "image size" is larger then the window.
Okay that might be the problem.
Do you also know how to change the size of the canvas to the size of the loaded photo? -
@mrjj said in programmatically promote a widget:
and it does allow scroll if "image size" is larger then the window.
Okay that might be the problem.
Do you also know how to change the size of the canvas to the size of the loaded photo?@hobbyProgrammer
Hi
The widget is the canvas.
The image is resized to the widget.So you can set
scribbleArea->setMinimumSize(500, 500); // "image size"
to the size of any image you load to make it that size.