Home > Mobile >  QT proxy class
QT proxy class

Time:11-23

When to add images to the list of qt tableview, found that use the tableview icon to display images have a small problem, is the picture not centered,
Then found in baidu solution, some bosses proposed using the proxy class,
So I am happy the proxy class inheritance QItemDelegate, produced a doubt,
A QLabel if my agent, so I can only go to load the fixed picture, can't go to load a late I specify image, or an online photo,

CodePudding user response:

You later also can call the specified label setPixmap method to set the background, but you need the address of a pointer to store the label for maintenance

CodePudding user response:

reference 1st floor Italink response:
you later also can call the specified label setPixmap method to set the background, but you need the address of a pointer to store the label for maintenance

When inherited QItemDelegate, agent qlabel can in the later call qlabel their function, bosses can't give you an example, I also want to call qlabel the function to set the pictures in the past, but don't know what to call the function, so I had to post for help bosses

CodePudding user response:

Not see why agent with QLabel, not directly with painter painting line?

CodePudding user response:

reference mideum reply: 3/f
is not very see why agent with QLabel, not directly with painter painting line?

Ah? Painter could be used directly to draw pictures in the table, this knowledge has really touched my blind spot, I baidu first study

CodePudding user response:

Using the proxy class painer, draw pictures, calculate the size of the cell and pictures, set up image centered offset will be pictures of the cell,
Void myDelegate: : paint (QPainter * painter, const QStyleOptionViewItem & amp; Option, const QModelIndex & amp; Const index)
{
If (index. The column ()==1)
{
QStyleOptionViewItem opt (option);
QStyledItemDelegate: : paint (painter, opt, index);
QImage image ("/home/untitled1/test. The PNG ");
Painter - & gt; DrawImage (option. The rect. (x) + option. The rect. The width () - image. Width ()/2, and option. The rect. Y () + ((option. The rect. Height () - image. Height ())/2), image).
}
}
  •  Tags:  
  • Qt
  • Related