Results 1 to 4 of 4

Thread: Qt3: How to update QLabel/QPixmap? Should I even be using those?

  1. #1
    Join Date
    Apr 2011
    Posts
    2
    Qt products
    Qt3
    Platforms
    Windows

    Default Qt3: How to update QLabel/QPixmap? Should I even be using those?

    As I understand it:
    QPainter: paints on a QPixmap.
    QPixmap: a surface. Displayed by a QLabel. Can be converted into a QImage, where I can do some stuff which I haven't read about yet.
    QLabel: used to display a QPixmap.

    So I have a button that makes an ellipse with certain parameters. I click it, nothing happens. I resize the window around the areas where it's supposed to be drawn, or minimize and restore the window, and voila there it is:
    cochlear4.PNG
    The white one is the one added by the button, the red ones were drawn inside the constructor of the class that defines the window (I think the parent of this particular tab would be QWidget _guiTab, you'll see that later on maybe).

    But I want it to update automatically. I have no idea how to do that (I don't want to make it poll or anything like that), so in lieu of an automatic solution I created an update button. Problem is, only QWidget has an update() function. I would've expected QPixmap, or QLabel to have this function (I don't know if QPixmap has already recognized that the QPainter has already drawn on it, or if QLabel simply hasn't refreshed QPixmap). And it seems it's not really a slot, so I have to make my own wrapper function inside this class that calls _guiTab->update(). It STILL doesn't work. Here's the affected code:

    header file:
    Qt Code:
    1. QLineEdit* _nameInput;
    2.  
    3. QComboBox* _frequencyBox;
    4. QPixmap *pixmap;
    5. QLabel *pixmaplabel;
    6. QPainter *drawstuff;
    7. QPushButton* _startStopButton;
    8. QPushButton *ellipse;
    9. QPushButton *updateButton;
    10. QPointArray splineone;
    11. QString* _subjectName;
    To copy to clipboard, switch view to plain text mode 

    This is all in the constructor:
    Qt Code:
    1. QFrame *testFrame = new QFrame(_guiTab);
    2. testFrame->setGeometry(350,20,650,620);
    3. testFrame->setFrameShadow(QFrame::Sunken);
    4. testFrame->setFrameShape(QFrame::Panel);
    5.  
    6. ellipse = new QPushButton("&Ellipse", modeFrame);
    7. ellipse->setGeometry(10,160,100,40);
    8. connect(ellipse,SIGNAL(clicked()),this,SLOT(doimplantscomeinellipses()));
    9.  
    10. updateButton = new QPushButton("&Update", modeFrame);
    11. updateButton->setGeometry(50,260,200,40);
    12. connect(updateButton,SIGNAL(clicked()),this,SLOT(updatewrapper()));
    13.  
    14. pixmaplabel = new QLabel(testFrame);
    15. pixmap = new QPixmap(650,600);
    16. pixmaplabel->setPixmap(*pixmap);
    17. pixmaplabel->setAutoResize(TRUE);
    18. drawstuff = new QPainter(pixmap);
    19. QPointArray splineone(4);
    20. splineone[0]=QPoint(50,50);
    21. splineone[1]=QPoint(150,0);
    22. splineone[2]=QPoint(150,150);
    23. splineone[3]=QPoint(400,200);
    24. drawstuff->setPen(Qt::red);
    25. drawstuff->drawRect(10,10,200,100);
    26. drawstuff->drawCubicBezier(splineone);
    27. drawstuff->drawRoundRect(200,180,400,320);
    28. _nameInput = new QLineEdit(modeFrame);
    29. _nameInput->setGeometry(10,50,280,45);
    30. connect(_nameInput,SIGNAL(textChanged ( const QString & )),this,SLOT(nameInputChanged( const QString & )));
    To copy to clipboard, switch view to plain text mode 

    and somewhere below that:
    Qt Code:
    1. void CochlearImplantExperiment_amt::doimplantscomeinellipses()
    2. {
    3. drawstuff->setPen(Qt::white);
    4. drawstuff->drawEllipse(100,100,400,150);
    5. }
    6. void CochlearImplantExperiment_amt::updatewrapper()
    7. {
    8. _guiTab->update();
    9. cout << "wtf";
    10. }
    To copy to clipboard, switch view to plain text mode 


    I'm not even sure that this combination of classes is the right thing to use. Previously I used QPainter drawing on a QCanvas, coupled with QCanvasView, but I found that there was no low level access to the points on a curve drawn on the QCanvas. You see, what I want to do is to make a curve/shape, and program a controller that guides a human to trace such a curve using vibrotactile signals. This curve is defined in the program because drawing with a mouse sucks, and besides the shapes that the user will be asked to trace IRL will be predefined shapes anyway. So I was thinking about converting QPixmap into a QImage later, and then operating on pixels of a specific colour in that QImage to make the controller find the path it's supposed to guide the user along. Is that possible with QImage/QPixmap or am I wasting my time?

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Qt3: How to update QLabel/QPixmap? Should I even be using those?

    I click it, nothing happens.
    It means the drawing code is not called.
    And its not called because the code in not in a paintEvent().
    Subclass QLabel and override ite paintEvent(), and put your specialized drawing code there.

    QWidget has an update() function. I would've expected QPixmap, or QLabel to have this function
    QLabel does.
    Read about the principals of OOP, and inheritance.

    Why do you use Qt3?
    Do you have a special restriction to use Qt3 only?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Apr 2011
    Posts
    2
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: Qt3: How to update QLabel/QPixmap? Should I even be using those?

    Thanks for the fast reply. I've been stuck for quite a while on this particular problem. Lemme get back to you on that once I've brushed up a lot more on C++...

    I can only use Qt 3.3.3, because the code compiles only on VS2003. Qt4 only has a VS2005 plugin, but VS2005 is much stricter, and besides, at one point in time, I tried - thousands of errors here and there thanks to VS2005's stricter code policies, not just in the code I'm responsible for, but also all of its libraries, which are also quite outdated at this point in time. As a university student, I gain precisely zero recognition for rewriting other people's code anyway - so yeah.

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Qt3: How to update QLabel/QPixmap? Should I even be using those?

    I can only use Qt 3.3.3, because the code compiles only on VS2003. Qt4 only has a VS2005 plugin, but VS2005 is much stricter, and besides, at one point in time, I tried - thousands of errors here and there thanks to VS2005's stricter code policies,
    I can hardly imagine that code will not compile on 2005 due to "strictness" of the compiler, which does compile on 2003.
    C++ hasn't changed THAT much over the two versions, such that ERROR will be given in one version that compiles on the other.
    I will accept this for warnings, and warning levels. but not for errors.
    The problem is probably more with the way you setup your project than with the move to a "stricter" compiler.
    And even if you where correct, why don't you use then MinGW for example?
    I would strongly recommend to you to move to Qt4!
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. dynamic QLabel update
    By satanowicz in forum Newbie
    Replies: 8
    Last Post: 25th May 2010, 23:20
  2. QLabel, QPixmap and ScaledContents
    By mhbeyle in forum Qt Programming
    Replies: 3
    Last Post: 28th November 2009, 09:11
  3. DrawLine over QPixmap within Qlabel
    By Qt Coder in forum Qt Programming
    Replies: 8
    Last Post: 26th March 2009, 12:21
  4. Rotate QPixmap set on QLabel
    By Qt Coder in forum Qt Programming
    Replies: 1
    Last Post: 18th March 2009, 12:08
  5. Replies: 2
    Last Post: 20th January 2009, 07:13

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.