You are not logged in.

Jean__

Beginner

  • "Jean__" is male
  • "Jean__" started this thread

Posts: 34

Location: Groningen

  • Send private message

1

Monday, December 31st 2007, 2:04pm

runtime jpeg's on a qlabel

I'm on my first app. I succeeded building a form with a sql table view and a qlabel with a splitter inbetween them using the designer.

Now at runtime, depending on which row the user clicks, I'd like to display some jpg's on the label.

How do I let a Qlabel display 4 or so jpg's at runtime, say file1.jpg, file2.jpg with some positioning, say at 0, 0, then 200, 0 etc?

How can I catch the onclick event from the tableview?

Good 2008 to you all and thanks.
Jean.

2

Monday, December 31st 2007, 2:27pm

RE: runtime jpeg's on a qlabel

use QGridLayout or another QLayout object

Source code

1
2
3
4
5
6
QWidget     * w = new QWidget;
QGridLayout * l = new QGridLayout( w );
l->addWidget( new QLabel, 0, 0 );
l->addWidget( new QLabel, 0, 1 );
l->addWidget( new QLabel, 1, 0 );
l->addWidget( new QLabel, 1, 1 );
Nicolas

This post has been edited 1 times, last edit by "Nicolas SOUCHON" (Dec 31st 2007, 2:33pm)


Jean__

Beginner

  • "Jean__" is male
  • "Jean__" started this thread

Posts: 34

Location: Groningen

  • Send private message

3

Monday, December 31st 2007, 3:50pm

Thanks again Nicolas, I got the jpg's working.
I used a the designer to add a horizontal layout and there I put 4 QLabels.
Then in code:

QPixmap *p1 = new QPixmap;
p1->load("/home/jean/serverd/Pix/Jpg/ana.avi/bscap0000.jpg");
pic1->setPixmap(*p1);

QPixmap *p2 etc.

(feel free to comment)

The pictures show up. :)
Now I can set the pictures depending on wich Sql row is clicked.

Good 2008

This post has been edited 4 times, last edit by "Jean__" (Dec 31st 2007, 4:04pm)


Jean__

Beginner

  • "Jean__" is male
  • "Jean__" started this thread

Posts: 34

Location: Groningen

  • Send private message

4

Monday, December 31st 2007, 4:35pm

If I use the designer only to put an QHBoxLayout and then try in code to add QLabels to it:

QLabel pic;
horizontalLayout->addWidget(pic);

I get:

error: ‘class QWidget’ has no member named ‘addWidget’

that horizontalLayout the designer has made seems not to be a QHBoxLayout but a QWidget.

I don't understand.

[edit]
putting 4 qlabels in an horizontallayout in the designer and then in code something like this:
QLabel *pic[4] = { pic0, pic1, pic2, pic3 }; // these are from the designer
works for me, I'm satisfied with that.

This post has been edited 2 times, last edit by "Jean__" (Dec 31st 2007, 5:34pm)


toki83

Beginner

  • "toki83" is male

Posts: 22

Location: Italy

  • Send private message

5

Wednesday, January 2nd 2008, 6:11pm

QLayout and inherited objects are not QWidgets, so every time you add a layout in QDesigner, QDesigner implicitly creates a QWidget in order to display the layout you have added.

This post has been edited 1 times, last edit by "toki83" (Jan 2nd 2008, 6:12pm)