I am new to Qt and Base on my research, I can resize a pixmap / image using scaled function I can. But when I run the program the image size is still the same. Here is the code
QStringList header; CastString Header = "Header1, Header 2"; Header = headerValues.split (","); UI- & gt; TableWidget_2- & gt; SetColumnCount (2); UI- & gt; TableWidget_2- & gt; SetHorizontalHeaderLabels (header); QStringList vertical headers; Qustring vertical header values = "vertical 1, vertical 2"; VerticalHeaders = verticalHeaderValues.split (","); UI- & gt; TableWidget_2- & gt; SetRowCount (1); UI-> Table Widget_2- & gt; Set vertical header labels (vertical headers); UI- & gt; TableWidget_2- & gt; HorizontalHeader () - & gt; SetDefaultSectionSize (150); UI- & gt; TableWidget_2- & gt; VerticalHeader () - & gt; SetDefaultSectionSize (150); UI- & gt; TableWidget_2- & gt; HorizontalHeader () - & gt; SetResizeMode (QHeaderView :: Fixed); UI- & gt; TableWidget_2- & gt; VerticalHeader () - & gt; SetResizeMode (QHeaderView :: Fixed); Caststring File Name = "/ Home / Markenanto / Desktop / Private / Projects / Fix Buttons / Printer Pages"; QPixmap photo (filename); Pic.scaled (20, 20, QT :: Unseen estimated concession, QT :: Fasttransformation); Qbrush brush (photo); QTableWidgetItem * items = new QTableWidgetItem (); Items, & gt; SetBackground (brush); Item- & gt; Set text ("add 5d"); UI- & gt; TableWidget_2- & gt; SetItem (0,0, item); If you read the QT documentation of QPixmap, you will see that the scale () function is declared as const and returns a QPixmap, which means that pixmap is not modified. What happens is that these functions come back to a scale version of pixmap. You have to store that place anywhere. In your case, you can pass the scaled pixmap to the only constructor constructor: QPixmap pic (filename); Qbrush Brush (pic.scaled (20, 20, QT :: Unseen estimated rheatio, QT :: faststationation)); If you have to use the same scaled pixmap later and there will be no use for the original, uncaleated pixmap, then you can directly access pic pixmap You should create a scale version of the source so that you do not end the same scaling operation several times: QPixmap pic (QPixmap (filename) .scaled (20, 20, Qt:: Undiscovered estimates Riatio, Qt :: FastTransformation);) If you need both scaled and unclored versions, then obviously you will need two pixels; For one more scaled version of the original version:
QPixmap pic (filename); QPixmap pixelsold (pic.scaled (20, 20, QT :: unseen estimate ratio, Qt :: FastTransformation));
No comments:
Post a Comment