//! [0] MyForm::MyForm(QWidget *parent) : QWidget(parent) { QFormBuilder builder; QFile file(":/forms/myWidget.ui"); file.open(QFile::ReadOnly); QWidget *myWidget = builder.load(&file, this); file.close(); QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(myWidget); setLayout(layout); }
bool QUICreator::create(const QString &path, int width, int height, QImage & img) { QFormBuilder builder; QFile file(path); if (!file.open(QFile::ReadOnly)) return false; QWidget *w = builder.load(&file); file.close(); if ( w ) { QPixmap p = QPixmap::grabWidget(w); img = p.toImage().scaled(width, height, Qt::KeepAspectRatio, Qt::SmoothTransformation); return true; } else return false; }
/** * Creates a new tab, and initializes a new conversation with given ip and name. * @brief MainWindow::createTab * @param cid Conversation id. * @param ip IPv4 address * @param name Nickname */ void MainWindow::createTab(QString cid, QString ip, QString name) { // Inflate tablelayout from file QFormBuilder builder; QFile file(FORM_TAB); file.open(QFile::ReadOnly); QWidget *tabLayout = builder.load(&file, this); file.close(); // Add layout to a new tab QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(tabLayout); QWidget *newTab = new QWidget(ui->tabgrpConversations); newTab->setLayout(layout); ui->tabgrpConversations->addTab(newTab, name + "/" + ip); //Add eventlisteners to new tab button, message text-box and smiley-list. QPushButton* btnSend = tabLayout->findChild<QPushButton*>("btnTabSend"); connect(btnSend, SIGNAL(clicked()), this, SLOT(sendConvoMessage())); QTextEdit* txtMsg = tabLayout->findChild<QTextEdit*>(CONVO_TAB_MSG_ID); txtMsg->installEventFilter(this); QListWidget* lstSmil = tabLayout->findChild<QListWidget*>("lstTabSmileys"); connect(lstSmil, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(on_lstSmileys_doubleClicked(QModelIndex))); for (int i = 0; i < smileys->count(); i++) { QListWidgetItem* qlwi = new QListWidgetItem(QIcon(RES_SMILEYS + QString::number(i) + ".png"), ""); lstSmil->addItem(qlwi); } Conversation* c = new Conversation(cid); if(controller->isExternal(ip)) //External ip { c->add(ip, name, true); } else c->add(ip, name); convos->append(c); }
void DesignerFields::initGUI( const QString &uiFile ) { QVBoxLayout *layout = new QVBoxLayout( this ); QFile f( uiFile ); f.open(QFile::ReadOnly); QFormBuilder builder; QWidget *wdg = builder.load( &f, this ); f.close(); if ( !wdg ) { kError() <<"No ui file found"; return; } mTitle = wdg->windowTitle(); mIdentifier = wdg->objectName(); layout->addWidget( wdg ); QStringList allowedTypes; allowedTypes << "QLineEdit" << "QTextEdit" << "QSpinBox" << "QCheckBox" << "QComboBox" << "QDateTimeEdit" << "KLineEdit" << "KDateTimeWidget" << "KDatePicker"; QList<QWidget*> list = wdg->findChildren<QWidget*>(); QWidget *it; Q_FOREACH( it, list ) { if ( allowedTypes.contains( it->metaObject()->className() ) ) { QString name = it->objectName(); if ( name.startsWith( "X_" ) ) { name = name.mid( 2 ); QWidget *widget = it; if ( !name.isEmpty() ) mWidgets.insert( name, widget ); if ( it->inherits( "QLineEdit" ) ) connect( it, SIGNAL( textChanged( const QString& ) ), SIGNAL( modified() ) ); else if ( it->inherits( "QSpinBox" ) ) connect( it, SIGNAL( valueChanged( int ) ), SIGNAL( modified() ) ); else if ( it->inherits( "QCheckBox" ) ) connect( it, SIGNAL( toggled( bool ) ), SIGNAL( modified() ) ); else if ( it->inherits( "QComboBox" ) ) connect( it, SIGNAL( activated( const QString& ) ), SIGNAL( modified() ) ); else if ( it->inherits( "QDateTimeEdit" ) ) connect( it, SIGNAL( valueChanged( const QDateTime& ) ), SIGNAL( modified() ) ); else if ( it->inherits( "KDateTimeWidget" ) ) connect( it, SIGNAL( valueChanged( const QDateTime& ) ), SIGNAL( modified() ) ); else if ( it->inherits( "KDatePicker" ) ) connect( it, SIGNAL( dateChanged( QDate ) ), SIGNAL( modified() ) ); else if ( it->inherits( "QTextEdit" ) ) connect( it, SIGNAL( textChanged() ), SIGNAL( modified() ) ); if ( !widget->isEnabled() ) mDisabledWidgets.append( widget ); } } } }