Results 1 to 11 of 11

Thread: Error in Q3Canvas Code...

  1. #1
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Error in Q3Canvas Code...

    Hi,

    I have created a MainWindow and am trying to paste the Q3Canvas item on it... But it is giving errors...
    Also i have tried to use the Zoom example given to zoom an image pasted on QCanvas but its not functioning fine.. None of the Menu options are working fine.. please check the code and tell me what can be the error...

    thanking you,
    Kapil
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Error in Q3Canvas Code...

    You didn't declare the actions in the ui file.

  3. #3
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Error in Q3Canvas Code...

    Hi...

    I have declared the actions.. i m pasting the part of the code which declares the actions..
    The major problem is that, canvas is coming on the frame and the image is getting displayed after the open function...
    But the Zoom In, Zoom Out and the Zoom Full funcs are not working..
    Also there is a small rectangle which is coming on the Canvas which i am not getting the way to remove... Please tell me how to remove that....

    ui_zoomsample.h
    Qt Code:
    1. class Ui_MainWindow
    2. {
    3. public:
    4. QAction *actionOpen;
    5. QAction *actionZoomIn;
    6. QAction *actionZoomOut;
    7. QAction *actionZoomNormal;
    8. QAction *actionFitToWindow;
    9. QWidget *centralwidget;
    10. QMenuBar *menubar;
    11. QMenu *menuFile;
    12. QStatusBar *statusbar;
    13.  
    14. void setupUi(QMainWindow *MainWindow)
    15. {
    16. MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
    17. MainWindow->resize(QSize(616, 667).expandedTo(MainWindow->minimumSizeHint()));
    18. actionOpen = new QAction(MainWindow);
    19. actionOpen->setObjectName(QString::fromUtf8("actionOpen"));
    20. actionZoomIn = new QAction(MainWindow);
    21. actionZoomIn->setObjectName(QString::fromUtf8("actionZoomIn"));
    22. actionZoomOut = new QAction(MainWindow);
    23. actionZoomOut->setObjectName(QString::fromUtf8("actionZoomOut"));
    24. actionZoomNormal = new QAction(MainWindow);
    25. actionZoomNormal->setObjectName(QString::fromUtf8("actionZoomNormal"));
    26. actionFitToWindow = new QAction(MainWindow);
    27. actionFitToWindow->setObjectName(QString::fromUtf8("actionFitToWindow"));
    28. centralwidget = new QWidget(MainWindow);
    29. centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
    30. MainWindow->setCentralWidget(centralwidget);
    31. menubar = new QMenuBar(MainWindow);
    32. menubar->setObjectName(QString::fromUtf8("menubar"));
    33. menubar->setGeometry(QRect(0, 0, 516, 19));
    34. menuFile = new QMenu(menubar);
    35. menuFile->setObjectName(QString::fromUtf8("menuFile"));
    36. MainWindow->setMenuBar(menubar);
    37. statusbar = new QStatusBar(MainWindow);
    38. statusbar->setObjectName(QString::fromUtf8("statusbar"));
    39. statusbar->setGeometry(QRect(0, 548, 516, 19));
    40. MainWindow->setStatusBar(statusbar);
    41.  
    42. menubar->addAction(menuFile->menuAction());
    43. menuFile->addAction(actionOpen);
    44. menuFile->addAction(actionZoomIn);
    45. menuFile->addAction(actionZoomOut);
    46. menuFile->addAction(actionZoomNormal);
    47. menuFile->addAction(actionFitToWindow);
    To copy to clipboard, switch view to plain text mode 

    imagezoomer.cpp
    Qt Code:
    1. #include "imagezoomer.h"
    2. #include <QtGui>
    3. #include <qdir.h>
    4. #include <QColor>
    5.  
    6. ImageZoomer::ImageZoomer(Ui::MainWindow *_mwin): mwin(_mwin)
    7. {
    8.  
    9. frame = new QFrame(mwin->centralwidget);
    10. frame->setGeometry(QRect(60, 70, 591, 571));
    11. frame->setFrameShape(QFrame::StyledPanel);
    12. frame->setFrameShadow(QFrame::Plain);
    13.  
    14. canvas = new Q3Canvas(frame);
    15. //canview = new Q3CanvasView(frame);
    16. //canview->setCanvas(canvas);
    17. canvas->setBackgroundColor(Qt::black);
    18. canvas->resize(400,400);
    19. canview = new Q3CanvasView(canvas,frame);
    20.  
    21. sarea = new QScrollArea(frame);
    22. sarea->setBackgroundRole(QPalette::Dark);
    23.  
    24. resize(500, 400);
    25. connect(mwin->actionOpen, SIGNAL(activated()), this, SLOT(open()));
    26. connect(mwin->actionZoomIn, SIGNAL(activated()), this, SLOT(zoomIn()));
    27. connect(mwin->actionZoomOut, SIGNAL(activated()), this, SLOT(zoomOut()));
    28. connect(mwin->actionZoomNormal, SIGNAL(activated()), this, SLOT(zoomNormal()));
    29. }
    30. ImageZoomer::~ImageZoomer()
    31. {
    32. }
    33.  
    34. void ImageZoomer::open()
    35. {
    36. QString filename = QFileDialog::getOpenFileName(this, tr("Open File"),QDir::currentPath());
    37.  
    38. if (!filename.isEmpty())
    39. {
    40. QImage image(filename);
    41. if (image.isNull())
    42. {
    43. QMessageBox::information(this, tr("Image Zoomer"),tr("Cannot load %1.").arg(filename));
    44. return;
    45. }
    46. canvas->setBackgroundPixmap(QPixmap::fromImage(image));
    47. scalefactor = 1.0;
    48. }
    49. }
    50.  
    51. void ImageZoomer::zoomIn()
    52. {
    53. scaleImage(1.25);
    54. }
    55.  
    56. void ImageZoomer::zoomOut()
    57. {
    58. scaleImage(0.8);
    59. }
    60.  
    61. void ImageZoomer::scaleImage(double factor)
    62. {
    63. int width,height;
    64. Q_ASSERT(canvas->backgroundPixmap());
    65. scalefactor *= factor;
    66. width =(int) scalefactor * fromImage.width();
    67. height =(int) scalefactor * fromImage.height();
    68. canvas->resize(width,height);
    69.  
    70. adjustScrollBar(sarea->horizontalScrollBar(), factor);
    71. adjustScrollBar(sarea->verticalScrollBar(), factor);
    72.  
    73. }
    74. void ImageZoomer::adjustScrollBar(QScrollBar *scrollBar, double factor)
    75. {
    76. scrollBar->setValue(int(factor * scrollBar->value() + ((factor - 1) * scrollBar->pageStep()/2)));
    77. }
    78. void ImageZoomer::fitToWindow()
    79. {
    80. scaleImage(1.0);
    81. }
    82.  
    83. void ImageZoomer::zoomNormal()
    84. {
    85. bool zoomnormal = mwin->actionZoomNormal->isChecked();
    86. sarea->setWidgetResizable(zoomnormal);
    87. if (!zoomnormal) {
    88. fitToWindow();
    89. }
    90. }
    To copy to clipboard, switch view to plain text mode 

    Kapil

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Error in Q3Canvas Code...

    This is what my compiler says:
    magezoomer.cpp: In constructor 'ImageZoomer::ImageZoomer(Ui::MainWindow*)':
    imagezoomer.cpp:27: error: 'class Ui_MainWindow' has no member named 'actionZoomNormal'
    imagezoomer.cpp: In member function 'void ImageZoomer::zoomNormal()':
    imagezoomer.cpp:84: error: 'class Ui_MainWindow' has no member named 'actionZoomNormal'

    BTW. What for do you use that scroll area at all?

    BTW2. What do you need that canvas for at all? You're not using any of its features here...
    Last edited by wysota; 24th March 2006 at 14:39.

  5. #5
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Error in Q3Canvas Code...

    Quote Originally Posted by wysota
    This is what my compiler says:



    BTW. What for do you use that scroll area at all?

    BTW2. What do you need that canvas for at all? You're not using any of its features here...
    Just check out the ui_zoomsample.h i have pasted in the previous reply...
    there is the statement:

    QAction *actionZoomNormal

    just check it in the ui_zoomsample.h i have sent with the zip.. it also has it..
    i have cross checked all and its working perfectly for me..
    i am pasting the image which shows the problem...

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Error in Q3Canvas Code...

    But the ui file doesn't have it.

    What about answers to my other ("BTW") questions?

  7. #7
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Error in Q3Canvas Code...

    Quote Originally Posted by wysota
    But the ui file doesn't have it.

    What about answers to my other ("BTW") questions?
    Hi...

    I have sent the ui_zoomsample.h file.. just check that... it has the QAction defined.. I can't say why it is not coming at ur end...

    Scroll Area
    I need the display the desing on the QCanvas.. Now the Design FIle size is big enough and does not fit into the QCanvas size defined.. so i have created a scroll area which would help me scroll the entire design , top to bottom and left to right...
    For this reason i have put on the scroll area...

    [HTML]BTW2. What do you need that canvas for at all? You're not using any of its features here...[/HTML]

    I am using QCanvas for displaying of the image.. as u had told me earlier that QCanvas helps me put the objects on the Canvas independntly... u had also told me that it is useful when i have to select individual objects.. now what i have to do is to select seperate objects i.e. user should be able to select rectangle drawn on QCanvas and highlight it without a need to repaint the entire design... this is why i have thought of using QCanvas.
    As i told you earlier, in my problem i have a huge design which would not fit on the screen and user will have to scroll left-right and up-down to view it..

    I am attaching an image of exactly what i want to draw... Its the smallest part of the entire design...its a tile... My design would comprise of 1000 such tiles..

    Please check it... You will get the idea of what i need to draw and why QCanvas is used..
    Kapil
    Attached Images Attached Images

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Error in Q3Canvas Code...

    1. Did you have a look and understand the canvas example bundled with Qt? Because from the nature of your questions I have a very strong doubt about it. You are asking lots of questions about the canvas and all of them can be answered just by looking at that example. We are not here to think for you or to do your work for you. We can help you but we're not your eployees -- you should really try to understand QCanvas if you try to use it. Or don't use it if you don't understand it.

    2. Looking at the thumbnail I'd say you don't need the canvas here. If you have trouble comprehending it, maybe you should reconsider using some different, easier approach.

  9. The following user says thank you to wysota for this useful post:

    Kapil (25th March 2006)

  10. #9
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Error in Q3Canvas Code...

    hi,

    Thanks for the reply...
    I know you are here to help me and not to do the work for me.. i would have never put on the image but just thought that i have not been able to clear what i want and thus the image should make it clear to you what i want as you wanted to know fro what i want to use QCanvas...
    i would defenitely go thru the example and wuld try to minimize asking doubts...


    As u said that you feel it can be solved using other approach.. can you tell me what can be a better approach to it so that in future i dont get confused on what approach to use for what...

    thanking you yet again...

    with regards,
    Kapil

  11. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Error in Q3Canvas Code...

    You should really start by reading the docs and examples provided with Qt. Canvas has some special capabilities, they are explained in the docs.

    When you are designing an application, you have to be sure what you are doing. If you're not convinced that your approach is correct then you should go back to the drawing board and think why you chose one way and not the other. And an answer that someone told you you could use it is not a good answer.

  12. #11
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Error in Q3Canvas Code...

    Quote Originally Posted by wysota
    You should really start by reading the docs and examples provided with Qt. Canvas has some special capabilities, they are explained in the docs.

    When you are designing an application, you have to be sure what you are doing. If you're not convinced that your approach is correct then you should go back to the drawing board and think why you chose one way and not the other. And an answer that someone told you you could use it is not a good answer.
    okie.. i would check on the docs properly and would finalize the approach..

    Thanks a lot for ur help and suggestion..

Similar Threads

  1. copyright and gpl
    By janus in forum General Discussion
    Replies: 8
    Last Post: 21st October 2008, 02:13
  2. Qt Cryptographic Architecture
    By vermarajeev in forum Qt Programming
    Replies: 6
    Last Post: 9th February 2007, 14:15
  3. Problem closing a QMainWindow in Qt4.2
    By ian in forum Qt Programming
    Replies: 11
    Last Post: 17th October 2006, 01:49
  4. problem with linking
    By mickey in forum Qt Programming
    Replies: 49
    Last Post: 12th August 2006, 22:41

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.