mirror of
https://gitee.com/drabel/LibQQt.git
synced 2025-01-04 10:18:44 +08:00
更新不规则widget的居中效果代码
This commit is contained in:
parent
67811b7ee1
commit
027af460ab
@ -53,9 +53,9 @@ void QQtIrregularLabel::makeMaskWidget ( void )
|
||||
{
|
||||
x0 = ( resultImage.width() - normalImage.width() ) / 2;
|
||||
y0 = ( resultImage.height() - normalImage.height() ) / 2;
|
||||
//不会出现下边的代码
|
||||
x0 = x0 < 0 ? 0 : x0;
|
||||
y0 = y0 < 0 ? 0 : y0;
|
||||
//不会出现下边的代码 不能出现下边的代码
|
||||
//x0 = x0 < 0 ? 0 : x0;
|
||||
//y0 = y0 < 0 ? 0 : y0;
|
||||
}
|
||||
|
||||
if ( alignment().testFlag ( Qt::AlignLeft ) )
|
||||
|
@ -77,12 +77,34 @@ void QQtIrregularWidget::resizeEvent ( QResizeEvent* event )
|
||||
pixmap = QPixmap::fromImage ( image() );
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
#if 0
|
||||
//本控件不再使用QIcon
|
||||
//偶尔会有重影,所以resize的频率不要太高,尤其在缩小的时候。
|
||||
pixmap = QIcon ( QPixmap::fromImage ( image() ) ).pixmap ( resultImage.size(),
|
||||
QIcon::Normal, QIcon::On );
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
int w0, h0;
|
||||
w0 = resultImage.width() - pixmap.width();
|
||||
h0 = resultImage.height() - pixmap.height();
|
||||
|
||||
if ( w0 < 0 && h0 < 0 )
|
||||
pixmap = QPixmap::fromImage ( image()
|
||||
.scaled ( resultImage.width(), resultImage.height(), Qt::KeepAspectRatio )
|
||||
);
|
||||
else if ( w0 < 0 )
|
||||
pixmap = QPixmap::fromImage ( image()
|
||||
.scaled ( resultImage.width(), image().height(), Qt::KeepAspectRatio )
|
||||
);
|
||||
else if ( h0 < 0 )
|
||||
pixmap = QPixmap::fromImage ( image()
|
||||
.scaled ( image().width(), resultImage.height(), Qt::KeepAspectRatio )
|
||||
);
|
||||
else
|
||||
pixmap = QPixmap::fromImage ( image() );
|
||||
#endif
|
||||
|
||||
//QQtWidget里面,StylePainter自动居中绘制,这里,手动居中绘制。
|
||||
//从合理位置开始绘制 很可能从中间开始绘制
|
||||
int x0, y0;
|
||||
|
@ -9,6 +9,12 @@
|
||||
|
||||
#include "qqtwidgets.h"
|
||||
|
||||
/**
|
||||
* @brief The QQtPushButton class
|
||||
* 原装Button在嵌入式板子上无法处理掉Hover问题。
|
||||
* QSS里设置也可以,把HOVER设置为和NORMAL一样,只是QSS代码量过大。
|
||||
* 原装Pushbutton需要设置setFlat以防止出现default button框。
|
||||
*/
|
||||
class QQTSHARED_EXPORT QQtPushButton : public QPushButton
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -49,6 +49,9 @@ MainWindow::MainWindow ( QWidget* parent ) :
|
||||
|
||||
|
||||
//other
|
||||
//ui->widget_30->setParent ( 0 );
|
||||
//ui->widget_30->show();
|
||||
|
||||
ui->widget_15->setPixmap ( conf_root ( "a1.png" ) );
|
||||
ui->widget_15->setImageStyle ( QQtWidget::QQTZOOMWIDTH );
|
||||
ui->widget_15->installEventFilter ( clicker );
|
||||
@ -160,6 +163,10 @@ MainWindow::MainWindow ( QWidget* parent ) :
|
||||
ui->listWidget->addItems ( items );
|
||||
connect ( ui->listWidget, SIGNAL ( currentItemChanged ( QListWidgetItem*, QListWidgetItem* ) ),
|
||||
this, SLOT ( currentItemChanged ( QListWidgetItem*, QListWidgetItem* ) ) );
|
||||
|
||||
//ui->label_9->setAlignment ( Qt::AlignCenter );
|
||||
ui->label_9->setPixmap ( QPixmap ( conf_root ( "a1.png" ) ) );
|
||||
ui->label_9->installEventFilter ( clicker );
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
|
@ -18,7 +18,7 @@
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="currentIndex">
|
||||
<number>7</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab_4">
|
||||
<attribute name="title">
|
||||
@ -268,24 +268,30 @@
|
||||
<attribute name="title">
|
||||
<string>Other mask</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="0" column="0">
|
||||
<widget class="QQtIrregularWidget" name="widget_15" native="true"/>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QQtIrregularWidget" name="widget_16" native="true"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QQtIrregularWidget" name="widget_17" native="true"/>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QQtIrregularWidget" name="widget_18" native="true"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QQtIrregularWidget" name="widget_19" native="true"/>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QQtIrregularWidget" name="widget_20" native="true"/>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_10">
|
||||
<item>
|
||||
<widget class="QWidget" name="widget_30" native="true">
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="0" column="0">
|
||||
<widget class="QQtIrregularWidget" name="widget_15" native="true"/>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QQtIrregularWidget" name="widget_16" native="true"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QQtIrregularWidget" name="widget_17" native="true"/>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QQtIrregularWidget" name="widget_18" native="true"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QQtIrregularWidget" name="widget_19" native="true"/>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QQtIrregularWidget" name="widget_20" native="true"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
@ -559,6 +565,19 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QQtIrregularLabel" name="label_9">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>70</x>
|
||||
<y>80</y>
|
||||
<width>81</width>
|
||||
<height>61</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
|
Loading…
x
Reference in New Issue
Block a user