Hai,
I am doing a project which needs a Qpainter to draw line but Qpainter donot work when we apply a style sheet to the frame where we have to draw the line
Hai,
I am doing a project which needs a Qpainter to draw line but Qpainter donot work when we apply a style sheet to the frame where we have to draw the line
This works ok:
Qt Code:
Q_OBJECT public: setStyleSheet( "Frame{ background: blue }" ); } protected: p.drawLine( rect().topLeft(), rect().bottomRight() ); p.drawText( rect().center(), "works!" ); } };To copy to clipboard, switch view to plain text mode
can you provide me with an example. pls
Since iam using the form window , i cannot apply this code , please give me an Qt example of an frame with Style sheet(background image) and Qpainter drawing lines on it
thanx for your help but it doesnt work and gives errors while we run it. can you please give some more details
You only have to change one line... clearly too hard:
and it looks like:Qt Code:
#include <QtGui> #include <QDebug> Q_OBJECT public: // setStyleSheet( "Frame{ background: blue }" ); setStyleSheet( "Frame{ background-image: url(plasma.png); }" ); } protected: p.drawLine( rect().topLeft(), rect().bottomRight() ); p.drawText( rect().center(), "works!" ); } }; int main(int argc, char *argv[]) { Frame m; m.show(); return app.exec(); } #include "main.moc"To copy to clipboard, switch view to plain text mode
simple_example.jpg
with a 64x64 tile background.
If you do not share the errors then you cannot expect corrections.
I already did.can you provide me with an example. pls
What errors ? It seems to work ok for ChrisW67.thanx for your help but it doesnt work and gives errors while we run it. can you please give some more details
in my progrm i am using 4frames(UI). I use show/hide frames using buttons. I have two draw a line in the 3rd frame. I have used the code
Qt Code:
{ linepen.setWidth(25); linepen.setCapStyle(Qt::RoundCap); painter.setPen(linepen); painter.drawLine(point,point2); }To copy to clipboard, switch view to plain text mode
since i have used the painter(this) the drawing is done on the main window so i cannot see the line on the frame. since frames(with background images) are placed over the main window.
Now i try to use painter(ui->frame3)
But it doesn't work. pls help me, thanks in advance
Last edited by wysota; 17th August 2011 at 22:41. Reason: missing [code] tags
Asked here already. What part of the sample code you don't understand ?
The (default) painting of the child will happen after the painting of the parent. If you override the paint event of the parent then why do you expect that the painting behaviour of a child widget will be changed? You want to override the paint event of the child widget.
"We can't solve problems by using the same kind of thinking we used when we created them." -- Einstein
If you are posting code then please use [code] [/code] tags around it - makes addressing the problem easier.
Bookmarks