Is it possible to place all controls I need directly to QMainWIndow? So there is no more need of any "foundation" widgets?
Printable View
Is it possible to place all controls I need directly to QMainWIndow? So there is no more need of any "foundation" widgets?
Well, I simply do not get it anymore. Here is the code. Now I want to add an QTableWidget near QGLWidget and I get same problem over again. I add to layout using:Code:
m_pVLayout->addLayout(m_pHLayout); // add horiz. layout to vertical layout m_pMainLayout->addLayout(m_pVLayout); // adds vert. layout to main layout m_pMainLayout->addWidget(m_pMerchandizeTable); // adds merchandize table to layout //m_pMainLayout->addWidget(pTWidget); // test //setLayout(m_pVLayout); // sets main layout on widget setLayout(m_pMainLayout); // sets main layout on widget
and table widget is visibible, but in upper left corner again. Why????!!!
What widget do you call the setLayout() method on? And why can't you use Qt Designer?
Well, setLayout is called on class COperationWindow (derived from QWidget), which contains QGLWidget, QLabel and three QPusbuttons. Here is a code:I do not use designet because I simply do not like it. And by the way, Qlabel DOES NOT show any text and this is simply driving me mad right now. And I know I've momentaly commented the code regarding QTableWidget, it's for testing purposes only, nevertheless, once qtablewidget code is uncommented the problem remains.Code:
#include "COperationWIndow.h" //COperationWIndow::COperationWIndow(QWidget* pParent) : QDockWidget(pParent) { //setAllowedAreas(Qt::LeftDockWidgetArea); // sets allowed dock area //setWindowOpacity(rDefaultWindowOpacity); // sets window opacity setWindowTitle(trUtf8("Jedilni list")); // sets window title //QFont m_cFont("Mom´sTypewriter", 72, QFont::Bold); // sets up font //m_cFont.setStretch(QFont::UltraCondensed); // sets strech factor // sets black background for this window setAutoFillBackground(true); m_cPalette=this->palette(); // gets current pallete of current widget this->setPalette(m_cPalette); // layout creation Q_CHECK_PTR(m_pVLayout); // checks creation Q_CHECK_PTR(m_pHLayout); // checks creation Q_CHECK_PTR(m_pMainLayout); // checks creation // creates merchandize browser m_pMerchandizeBrowser=new CMerchandizeBrowser(this); // creates new merchandize selector //m_pMerchandizeBrowser=new CMerchandizeBrowser(pParent); // creates new merchandize selector Q_CHECK_PTR(m_pMerchandizeBrowser); // checks creation // creates Left Selector pushbutton //m_pLeftButtonMerchandizeSelector=new QPushButton(trUtf8("Izbira levega artikla"), pParent); Q_CHECK_PTR(m_pLeftButtonMerchandizeSelector); // checks creation //m_pLeftButtonMerchandizeSelector->setFlat(true); // sets flat flag // sets new size //m_pLeftButtonMerchandizeSelector->resize(iMerchandizeButtonSelectorWidth, iMerchandizeButtonSelectorHeight); connect(m_pLeftButtonMerchandizeSelector, SIGNAL(clicked()), this, SLOT(showLeftMerchandize())); // creates merchandizer confirmer Q_CHECK_PTR(m_pButtonMerchandizeConfirmer); connect(m_pButtonMerchandizeConfirmer, SIGNAL(clicked()), this, SLOT(chooseMerchandize())); // creates Right Selector pushbutton //m_pRightButtonMerchandizeSelector=new QPushButton(trUtf8("Izbira desnegs artikla"), pParent); Q_CHECK_PTR(m_pRightButtonMerchandizeSelector); // checks creation //m_pRightButtonMerchandizeSelector->setFlat(true); // sets flat flag // sets new size //m_pRightButtonMerchandizeSelector->resize(iMerchandizeButtonSelectorWidth, iMerchandizeButtonSelectorHeight); connect(m_pRightButtonMerchandizeSelector, SIGNAL(clicked()), this, SLOT(showRightMerchandize())); // left button color setup m_cPalette=m_pLeftButtonMerchandizeSelector->palette(); // gets current pallete of button "Left" m_pLeftButtonMerchandizeSelector->setPalette(m_cPalette); // sets new pallete m_pLeftButtonMerchandizeSelector->setFont(m_cFont); // sets new font // confirmer button color setup m_cPalette=m_pButtonMerchandizeConfirmer->palette(); // gets current pallete of button "Left" m_pButtonMerchandizeConfirmer->setPalette(m_cPalette); // sets new pallete m_pButtonMerchandizeConfirmer->setFont(m_cFont); // sets new font // right button color setup m_cPalette=m_pRightButtonMerchandizeSelector->palette(); // gets current pallete of button "Right" m_pRightButtonMerchandizeSelector->setPalette(m_cPalette); // sets new pallete m_pRightButtonMerchandizeSelector->setFont(m_cFont); // sets new font // TODO: show selected merchandize name and price // table of ordered merchandize creation /* m_pMerchandizeTable=new QTableWidget(this); // creates new table Q_CHECK_PTR(m_pMerchandizeTable); // checks creation m_pMerchandizeTable->setColumnCount(iNrColumns); // sets number of columns m_pMerchandizeTable->setRowCount(iNrRows); // sets number of rows */ // selected merchandize name label widget Q_CHECK_PTR(m_pMerchandizeNameLabel); // checks creation m_cPalette=m_pMerchandizeNameLabel->palette(); // geta label palette m_pMerchandizeNameLabel->setFont(labelFont); // sets font // sets selected merchandize name m_pMerchandizeNameLabel->setText(m_pMerchandizeBrowser->getMerchandizeName(m_pMerchandizeBrowser->getSelected())); m_pMerchandizeNameLabel->setAlignment(Qt::AlignCenter); // set text justification to "centering" qDebug() << m_pMerchandizeBrowser->getMerchandizeName(m_pMerchandizeBrowser->getSelected()); // layouts setup m_pHLayout->addWidget(m_pLeftButtonMerchandizeSelector); // adds button to horiz. layout m_pHLayout->addWidget(m_pButtonMerchandizeConfirmer); // adds a button to horiz. layout m_pHLayout->addWidget(m_pRightButtonMerchandizeSelector); // adds button to horiz. layout m_pVLayout->addWidget(m_pMerchandizeBrowser); // adds merchandize selector to vertical layout m_pVLayout->addWidget(m_pMerchandizeNameLabel); // adds merchandize name label to vertical layout m_pVLayout->addLayout(m_pHLayout); // add horiz. layout to vertical layout m_pMainLayout->addLayout(m_pVLayout); // adds vert. layout to main layout //m_pMainLayout->addWidget(m_pMerchandizeTable); // adds merchandize table to layout setLayout(m_pMainLayout); // sets main layout on widget // creats new timer, binded to main application object /* QPointer<QTimer> m_pAdvertisementTimer=new QTimer(this); Q_CHECK_PTR(m_pAdvertisementTimer); // checks creation connect(m_pAdvertisementTimer, SIGNAL(timeout()), this, SLOT(startAdvertising())); m_pAdvertisementTimer->start(iAdvertisingTimeout); // restarts advertisement timer */ } void COperationWIndow::showLeftMerchandize() { m_iSelected=m_pMerchandizeBrowser->getSelected()-1; // selects left merchandize m_pMerchandizeBrowser->setSelected(m_iSelected); m_pMerchandizeNameLabel->setText(m_pMerchandizeBrowser->getMerchandizeName(m_pMerchandizeBrowser->getSelected())); m_pMerchandizeNameLabel->setAlignment(Qt::AlignCenter); // set text justification to "centering" m_pMerchandizeBrowser->update(); //m_pAdvertisementTimer->start(iAdvertisingTimeout); // restarts advertisement timer } void COperationWIndow::showRightMerchandize() { m_iSelected=m_pMerchandizeBrowser->getSelected()+1; // selects left merchandize m_pMerchandizeBrowser->setSelected(m_iSelected); m_pMerchandizeNameLabel->setText(m_pMerchandizeBrowser->getMerchandizeName(m_pMerchandizeBrowser->getSelected())); m_pMerchandizeNameLabel->setAlignment(Qt::AlignCenter); // set text justification to "centering" m_pMerchandizeBrowser->update(); // showa selected merchandize //m_pAdvertisementTimer->start(iAdvertisingTimeout); // restarts advertisement timer } // slot for choosing merchandize void COperationWIndow::chooseMerchandize() { } // slot for showing advertisement banners void COperationWIndow::startAdvertising() { } COperationWIndow::~COperationWIndow() { }
You shouldn't pass "this" to layouts' constructors, because they will call setLayout() on the parent.
Like it or not, but it would take you only a couple of minutes to set up this widget in Qt Designer.
Because you should use QPalette::WindowText instead of QPalette::Text and you have to set the changed palette back on the label to see the effect.
Yessssssss! But whatever I do, I get same result: QTableWidget is in upper left corner and therefore this is NOT ok. I want result excatly as on your pic.
That's weird, because I've just uncommented the m_pMerchandizeTable lines (including the one with addWidget()). Run "make clean" and make sure you don't pass any parents to layout constructors.