Seite 1 von 1

[teilw. gelöst] Wie definiert man Margins bei QTableWidget

Verfasst: 7. Januar 2009 12:42
von nasahl
Hallo,

ich möchte innerhalb einer Table einen Margin setzen.

Bei Q3Table war dies mit setMargin(...) ziemlich einfach (intern eine Q3Frame-Methode).

Bei QTableWidget gibt es diese Funktion nicht mehr, da QFrame keine Margins mehr verwaltet. Die Methode setContentsMargins(...) funktioniert auch nicht, da sie permanent von QT-internen Funktionen aufgerufen wird und den Margin dabei zurücksetzt.

Kann man mit QT4 die Margins einer Table gar nicht mehr setzen oder funktioniert das anders?


Christof

Re: Wie definiert man Margins bei QTableWidget

Verfasst: 8. Januar 2009 07:40
von macman
nasahl hat geschrieben:Die Methode setContentsMargins(...) funktioniert auch nicht,
Dann machst Du was falsch. Wenn Du z.B. einen Wert von 10 einsetzt, wer sollte da dann etwas zurück setzen?

Verfasst: 8. Januar 2009 12:13
von nasahl
Ich weiss nicht ob der Stack viel hilft:

Code: Alles auswählen

>	QtGuid4.dll!QWidget::setContentsMargins(int left=9, int top=9, int right=9, int bottom=9)  Line 5822	C++
 	QtGuid4.dll!QFrame::setFrameRect(const QRect & r={...})  Line 501	C++
 	QtGuid4.dll!QAbstractScrollAreaPrivate::layoutChildren()  Line 353	C++
 	QtGuid4.dll!QAbstractScrollArea::setViewportMargins(int left=15, int top=22, int right=0, int bottom=0)  Line 808	C++
 	QtGuid4.dll!QTableView::updateGeometries()  Line 1327	C++
 	WolfTable.exe!MyTable::updateGeometries()  Line 344	C++
 	QtGuid4.dll!QAbstractItemView::qt_metacall(QMetaObject::Call _c=InvokeMetaMethod, int _id=23, void * * _a=0x0012f274)  Line 230 + 0xe bytes	C++
 	QtGuid4.dll!QTableView::qt_metacall(QMetaObject::Call _c=InvokeMetaMethod, int _id=54, void * * _a=0x0012f274)  Line 103 + 0x14 bytes	C++
 	QtGuid4.dll!QTableWidget::qt_metacall(QMetaObject::Call _c=InvokeMetaMethod, int _id=54, void * * _a=0x0012f274)  Line 128 + 0x14 bytes	C++
 	WolfTable.exe!MyTable::qt_metacall(QMetaObject::Call _c=InvokeMetaMethod, int _id=54, void * * _a=0x0012f274)  Line 103 + 0x65 bytes	C++
 	QtCored4.dll!QMetaObject::activate(QObject * sender=0x00c95970, int from_signal_index=77, int to_signal_index=77, void * * argv=0x00000000)  Line 2979 + 0x29 bytes	C++
 	QtCored4.dll!QMetaObject::activate(QObject * sender=0x00c95970, const QMetaObject * m=0x6583b2c4, int local_signal_index=9, void * * argv=0x00000000)  Line 3049 + 0x15 bytes	C++
 	QtGuid4.dll!QHeaderView::geometriesChanged()  Line 269 + 0x13 bytes	C++
 	QtGuid4.dll!QHeaderView::viewportEvent(QEvent * e=0x0012f73c)  Line 2280	C++
 	QtGuid4.dll!QAbstractScrollAreaPrivate::viewportEvent(QEvent * event=0x0012f73c)  Line 80 + 0x26 bytes	C++
 	QtGuid4.dll!QAbstractScrollAreaFilter::eventFilter(QObject * o=0x00c97f70, QEvent * e=0x0012f73c)  Line 91 + 0x29 bytes	C++
 	QtCored4.dll!QCoreApplicationPrivate::sendThroughObjectEventFilters(QObject * receiver=0x00c97f70, QEvent * event=0x0012f73c)  Line 672 + 0x13 bytes	C++
 	QtGuid4.dll!QApplicationPrivate::notify_helper(QObject * receiver=0x00c97f70, QEvent * e=0x0012f73c)  Line 3777 + 0x11 bytes	C++
 	QtGuid4.dll!QApplication::notify(QObject * receiver=0x00c97f70, QEvent * e=0x0012f73c)  Line 3748 + 0x10 bytes	C++
 	QtCored4.dll!QCoreApplication::notifyInternal(QObject * receiver=0x00c97f70, QEvent * event=0x0012f73c)  Line 565 + 0x13 bytes	C++
 	QtCored4.dll!QCoreApplication::sendEvent(QObject * receiver=0x00c97f70, QEvent * event=0x0012f73c)  Line 193 + 0x39 bytes	C++
 	QtGuid4.dll!QWidgetPrivate::setFont_helper(const QFont & font={...})  Line 3978 + 0xe bytes	C++
 	QtGuid4.dll!QWidgetPrivate::resolveFont()  Line 3936 + 0x4c bytes	C++
 	QtGuid4.dll!QWidgetPrivate::setFont_helper(const QFont & font={...})  Line 3969	C++
 	QtGuid4.dll!QWidgetPrivate::resolveFont()  Line 3936 + 0x4c bytes	C++
 	QtGuid4.dll!QWidgetPrivate::setFont_helper(const QFont & font={...})  Line 3969	C++
 	QtGuid4.dll!QWidgetPrivate::resolveFont()  Line 3936 + 0x4c bytes	C++
 	QtGuid4.dll!QWidget::event(QEvent * event=0x0012fe00)  Line 6984	C++
 	QtGuid4.dll!QFrame::event(QEvent * e=0x0012fe00)  Line 636	C++
 	QtGuid4.dll!QAbstractScrollArea::event(QEvent * e=0x0012fe00)  Line 875 + 0xc bytes	C++
 	QtGuid4.dll!QAbstractItemView::event(QEvent * event=0x0012fe00)  Line 1343	C++
 	QtGuid4.dll!QTableWidget::event(QEvent * e=0x0012fe00)  Line 2609	C++
 	QtGuid4.dll!QApplicationPrivate::notify_helper(QObject * receiver=0x0012ff38, QEvent * e=0x0012fe00)  Line 3781 + 0xf bytes	C++
 	QtGuid4.dll!QApplication::notify(QObject * receiver=0x0012ff38, QEvent * e=0x0012fe00)  Line 3748 + 0x10 bytes	C++
 	QtCored4.dll!QCoreApplication::notifyInternal(QObject * receiver=0x0012ff38, QEvent * event=0x0012fe00)  Line 565 + 0x13 bytes	C++
 	QtCored4.dll!QCoreApplication::sendEvent(QObject * receiver=0x0012ff38, QEvent * event=0x0012fe00)  Line 193 + 0x39 bytes	C++
 	QtGuid4.dll!QWidget::ensurePolished()  Line 8083 + 0xe bytes	C++
 	QtGuid4.dll!QWidget::setVisible(bool visible=true)  Line 6309	C++
 	QtGuid4.dll!QWidget::show()  Line 448 + 0x14 bytes	C++
 	WolfTable.exe!main(int argc=1, char * * argv=0x00b06b88)  Line 36	C++
 	WolfTable.exe!__tmainCRTStartup()  Line 597 + 0x19 bytes	C
 	WolfTable.exe!mainCRTStartup()  Line 414	C
 	kernel32.dll!7c816fd7() 	
 	[Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]	
Aber an dieser Stelle wird der manuell gesetzte Wert überschrieben. Es gibt sogar noch mehr Stellen die überschreiben. :cry:

Christof

[gelöst] Wie definiert man Margins bei QTableWidget

Verfasst: 12. Januar 2009 07:50
von nasahl
Hallo,

um den Thread ordentlich abzustellen gebe ich die Antwort nun selbst. Der Trolltech Support hat mir einen Tip gegeben: Man muss die Methode QTableWidget::updateGeometries() überschreiben:

Code: Alles auswählen

	void updateGeometries()
	{
		QTableWidget::updateGeometries();

		// Setzt die Margins (=StyleBox-Padding) um
		int margins_l = 20;
		int margins_u = 40;
		int margins_r = 80;
		int margins_d = 40;

		int width = 0;
		if (!verticalHeader()->isHidden()) {
			width = qMax(verticalHeader()->minimumWidth(),
				verticalHeader()->sizeHint().width());
			width = qMin(width, verticalHeader()->maximumWidth());
		}
		int height = 0;
		if (!horizontalHeader()->isHidden()) {
			height = qMax(horizontalHeader()->minimumHeight(),
				horizontalHeader()->sizeHint().height());
			height = qMin(height, horizontalHeader()->maximumHeight());
		}
		bool reverse = isRightToLeft();
		if (reverse)
			setViewportMargins(margins_l, margins_u + height, margins_r + width, margins_d);
		else
			setViewportMargins(width + margins_l, height + margins_u, margins_r, margins_d);
	}
So funktionierts