1
0
mirror of https://gitee.com/drabel/LibQQt.git synced 2025-01-04 10:18:44 +08:00

更新不规则widget的居中效果代码

This commit is contained in:
tianduanrui 2019-09-21 11:37:33 +08:00
parent 67811b7ee1
commit 027af460ab
5 changed files with 77 additions and 23 deletions

View File

@ -53,9 +53,9 @@ void QQtIrregularLabel::makeMaskWidget ( void )
{ {
x0 = ( resultImage.width() - normalImage.width() ) / 2; x0 = ( resultImage.width() - normalImage.width() ) / 2;
y0 = ( resultImage.height() - normalImage.height() ) / 2; y0 = ( resultImage.height() - normalImage.height() ) / 2;
//不会出现下边的代码 //不会出现下边的代码 不能出现下边的代码
x0 = x0 < 0 ? 0 : x0; //x0 = x0 < 0 ? 0 : x0;
y0 = y0 < 0 ? 0 : y0; //y0 = y0 < 0 ? 0 : y0;
} }
if ( alignment().testFlag ( Qt::AlignLeft ) ) if ( alignment().testFlag ( Qt::AlignLeft ) )

View File

@ -77,12 +77,34 @@ void QQtIrregularWidget::resizeEvent ( QResizeEvent* event )
pixmap = QPixmap::fromImage ( image() ); pixmap = QPixmap::fromImage ( image() );
#endif #endif
#if 1 #if 0
//本控件不再使用QIcon
//偶尔会有重影所以resize的频率不要太高尤其在缩小的时候。 //偶尔会有重影所以resize的频率不要太高尤其在缩小的时候。
pixmap = QIcon ( QPixmap::fromImage ( image() ) ).pixmap ( resultImage.size(), pixmap = QIcon ( QPixmap::fromImage ( image() ) ).pixmap ( resultImage.size(),
QIcon::Normal, QIcon::On ); QIcon::Normal, QIcon::On );
#endif #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自动居中绘制这里手动居中绘制。 //QQtWidget里面StylePainter自动居中绘制这里手动居中绘制。
//从合理位置开始绘制 很可能从中间开始绘制 //从合理位置开始绘制 很可能从中间开始绘制
int x0, y0; int x0, y0;

View File

@ -9,6 +9,12 @@
#include "qqtwidgets.h" #include "qqtwidgets.h"
/**
* @brief The QQtPushButton class
* Button在嵌入式板子上无法处理掉Hover问题
* QSS里设置也可以HOVER设置为和NORMAL一样QSS代码量过大
* Pushbutton需要设置setFlat以防止出现default button框
*/
class QQTSHARED_EXPORT QQtPushButton : public QPushButton class QQTSHARED_EXPORT QQtPushButton : public QPushButton
{ {
Q_OBJECT Q_OBJECT

View File

@ -49,6 +49,9 @@ MainWindow::MainWindow ( QWidget* parent ) :
//other //other
//ui->widget_30->setParent ( 0 );
//ui->widget_30->show();
ui->widget_15->setPixmap ( conf_root ( "a1.png" ) ); ui->widget_15->setPixmap ( conf_root ( "a1.png" ) );
ui->widget_15->setImageStyle ( QQtWidget::QQTZOOMWIDTH ); ui->widget_15->setImageStyle ( QQtWidget::QQTZOOMWIDTH );
ui->widget_15->installEventFilter ( clicker ); ui->widget_15->installEventFilter ( clicker );
@ -160,6 +163,10 @@ MainWindow::MainWindow ( QWidget* parent ) :
ui->listWidget->addItems ( items ); ui->listWidget->addItems ( items );
connect ( ui->listWidget, SIGNAL ( currentItemChanged ( QListWidgetItem*, QListWidgetItem* ) ), connect ( ui->listWidget, SIGNAL ( currentItemChanged ( QListWidgetItem*, QListWidgetItem* ) ),
this, SLOT ( 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() MainWindow::~MainWindow()

View File

@ -18,7 +18,7 @@
<item> <item>
<widget class="QTabWidget" name="tabWidget"> <widget class="QTabWidget" name="tabWidget">
<property name="currentIndex"> <property name="currentIndex">
<number>7</number> <number>0</number>
</property> </property>
<widget class="QWidget" name="tab_4"> <widget class="QWidget" name="tab_4">
<attribute name="title"> <attribute name="title">
@ -268,6 +268,9 @@
<attribute name="title"> <attribute name="title">
<string>Other mask</string> <string>Other mask</string>
</attribute> </attribute>
<layout class="QHBoxLayout" name="horizontalLayout_10">
<item>
<widget class="QWidget" name="widget_30" native="true">
<layout class="QGridLayout" name="gridLayout_3"> <layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0"> <item row="0" column="0">
<widget class="QQtIrregularWidget" name="widget_15" native="true"/> <widget class="QQtIrregularWidget" name="widget_15" native="true"/>
@ -289,6 +292,9 @@
</item> </item>
</layout> </layout>
</widget> </widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_7"> <widget class="QWidget" name="tab_7">
<attribute name="title"> <attribute name="title">
<string>button mask</string> <string>button mask</string>
@ -559,6 +565,19 @@
</item> </item>
</layout> </layout>
</widget> </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>
</widget> </widget>
</item> </item>