Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. programmatically promote a widget
Forum Updated to NodeBB v4.3 + New Features

programmatically promote a widget

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 4 Posters 1.4k Views 4 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hobbyProgrammer
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Why not just use the class directly ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      H 2 Replies Last reply
      0
      • SGaistS SGaist

        Hi,

        Why not just use the class directly ?

        H Offline
        H Offline
        hobbyProgrammer
        wrote on last edited by
        #3

        @SGaist What do you mean/how should I do that?

        1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          Why not just use the class directly ?

          H Offline
          H Offline
          hobbyProgrammer
          wrote on last edited by
          #4

          @SGaist

          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);
          }
          
          Pablo J. RoginaP SGaistS 2 Replies Last reply
          0
          • H hobbyProgrammer

            @SGaist

            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);
            }
            
            Pablo J. RoginaP Offline
            Pablo J. RoginaP Offline
            Pablo J. Rogina
            wrote on last edited by
            #5

            @hobbyProgrammer said in programmatically promote a widget:

            setCentralWidget(scribbleArea);
            

            I guess the central widget of your MainWindow object should be the QScrollArea...

            ...
            setCentralWidget(scrollArea);
            ...
            

            Upvote the answer(s) that helped you solve the issue
            Use "Topic Tools" button to mark your post as Solved
            Add screenshots via postimage.org
            Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            2
            • H hobbyProgrammer

              @SGaist

              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);
              }
              
              SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @hobbyProgrammer said in programmatically promote a widget:

              @SGaist

              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.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1
              • mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #7

                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.

                alt text

                H 3 Replies Last reply
                3
                • mrjjM mrjj

                  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.

                  alt text

                  H Offline
                  H Offline
                  hobbyProgrammer
                  wrote on last edited by
                  #8
                  This post is deleted!
                  1 Reply Last reply
                  0
                  • mrjjM mrjj

                    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.

                    alt text

                    H Offline
                    H Offline
                    hobbyProgrammer
                    wrote on last edited by
                    #9

                    @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.

                    1086a858-c132-45cc-856b-afb5992bcbea-image.png

                    after zooming in:
                    4e45093e-6dd5-45ed-b961-7ac07e3e8ad7-image.png

                    and this is how it looks when I don't size the app to my full screensize:

                    9dd8521c-a3ae-4065-819a-82ba22d3842b-image.png

                    1 Reply Last reply
                    0
                    • H Offline
                      H Offline
                      hobbyProgrammer
                      wrote on last edited by
                      #10
                      This post is deleted!
                      1 Reply Last reply
                      0
                      • mrjjM mrjj

                        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.

                        alt text

                        H Offline
                        H Offline
                        hobbyProgrammer
                        wrote on last edited by hobbyProgrammer
                        #11

                        @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?

                        mrjjM 1 Reply Last reply
                        0
                        • H hobbyProgrammer

                          @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?

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          @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.

                          1 Reply Last reply
                          0

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved