[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-look
Subject:    Help needed with a QGroupBox
From:       Thomas Zander <zander () xs4all ! nl>
Date:       2000-04-24 14:38:54
[Download RAW message or body]

Hi, I've been hacking at the control center [file assiciations] module. 
Mostly the layout. Since the dialog did not resize when the window did.
I put everything in a QGridLayout, and wanted to put the Iconbutton inside
a QGroupBox, creating a total hierarchy as the following:

QGridLayout
+- QGroupBox
 +- QHBoxLayout
  +- KIconLoaderButton

The QHBoxLayout is used because something has to go into the QGroupBox...

This works just fine:
  QHBoxLayout *hBox = new QHBoxLayout(this,KDialog::marginHint(), KDialog::spacingHint());
  lay->addLayout(hBox,1,3);

  iconButton = new KIconLoaderButton(this);
  iconButton->setIconType(KIcon::Desktop, KIcon::MimeType);
  connect(iconButton, SIGNAL(iconChanged(QString)), SLOT(updateIcon(QString)));
  iconButton->setFixedSize(50, 50);
  hBox->addWidget(iconButton,AlignLeft); 

While this code puts my Iconbutton totaly on the wrong spot: (about centered 
in the whole dialog)
  gb = new QGroupBox(i18n("Icon"), this);
  QHBoxLayout *hBox = new QHBoxLayout(gb,KDialog::marginHint(), KDialog::spacingHint());
  lay->addWidget(gb,1,3); 

//[same 2nd part as above]
  iconButton = new KIconLoaderButton(this);
  iconButton->setIconType(KIcon::Desktop, KIcon::MimeType);
  connect(iconButton, SIGNAL(iconChanged(QString)), SLOT(updateIcon(QString)));
  iconButton->setFixedSize(50, 50);
  hBox->addWidget(iconButton,AlignLeft); 


Could someone help me out here. As an attachment you'll find the patch with the 
code..
(patch -0 <filetypes.diff  from the dir where kdebase resides in)

Thanx!!
--
Thomas Zander                                                zander@microweb.nl
History repeats itself, it has to, nobody ever listens      OpenPGP key: 0588D5 

["filetypes.diff" (text/plain)]

--- kdebase/kcontrol/filetypes/filetypesview.cpp	Sun Apr 23 16:39:42 2000
+++ kdebase/kcontrol/filetypes/filetypesview_new.cpp	Mon Apr 24 16:34:22 2000
@@ -30,21 +30,45 @@
 FileTypesView::FileTypesView(QWidget *p, const char *name)
   : KCModule(p, name)
 {
-  QString wtstr;
-  setButtons(Cancel|Apply|Ok);
-  QVBoxLayout *wrapper = new QVBoxLayout(this, KDialog::marginHint(),
-					 KDialog::spacingHint());
-  QHBoxLayout *topLayout = new QHBoxLayout;
-
-  wrapper->addLayout(topLayout);
-  QGridLayout *leftLayout = new QGridLayout(2, 2);
-  topLayout->addLayout(leftLayout, 2);
+  QString wtstr;  //help string
+  QGroupBox *gb;  // group boxes
+  QGridLayout *lay = new QGridLayout(this,8,5);
+  lay->addRowSpacing(0,10);
+  lay->addRowSpacing(2,10);
+  lay->addRowSpacing(4,10);
+  lay->addRowSpacing(7,10);
+  lay->addColSpacing(0,10);
+  lay->addColSpacing(2,10);
+  lay->addColSpacing(4,10);
+
+  lay->setRowStretch(0,0);
+  lay->setRowStretch(1,0); // ROW_ICON
+  lay->setRowStretch(2,0);
+  lay->setRowStretch(3,5); // ROW_FILE_PATTERNS
+  lay->setRowStretch(4,0);
+  lay->setRowStretch(5,5); // ROW_APPLICATION..
+  lay->setRowStretch(6,10);
+  lay->setRowStretch(7,0); 
+
+  lay->setColStretch(0,0);
+  lay->setColStretch(1,1);
+  lay->setColStretch(2,0);
+  lay->setColStretch(3,1);
+  lay->setColStretch(4,0);
+
+  QGridLayout *left = new QGridLayout(this,2,1);
+  left->setRowStretch(0,1);
+  left->setRowStretch(1,0); // ROW BUTTONS
+  left->setColStretch(0,1);
+  left->setColStretch(1,1);
+
+  lay->addMultiCell(left,1,6,1,1);
 
   typesLV = new QListView(this);
   typesLV->setRootIsDecorated(true);
 
   typesLV->addColumn(i18n("Known Types"));
-  leftLayout->addMultiCellWidget(typesLV, 0, 0, 0, 1);
+  left->addMultiCellWidget(typesLV, 0,0,0,1);
   connect(typesLV, SIGNAL(selectionChanged(QListViewItem *)),
           this, SLOT(updateDisplay(QListViewItem *)));
 
@@ -55,35 +79,37 @@
   QPushButton *addTypeB = new QPushButton(i18n("&Add..."), this);
   connect(addTypeB, SIGNAL(clicked()),
           this, SLOT(addType()));
-  leftLayout->addWidget(addTypeB, 1, 0);
+  left->addWidget(addTypeB, 1,0);
 
   QWhatsThis::add( addTypeB, i18n("Click here to add a new file type.") );
 
   QPushButton *removeTypeB = new QPushButton(i18n("&Remove"), this);
   connect(removeTypeB, SIGNAL(clicked()),
           this, SLOT(removeType()));
-  leftLayout->addWidget(removeTypeB, 1, 1);
+  left->addWidget(removeTypeB, 1, 1);
 
   QWhatsThis::add( removeTypeB, i18n("Removes the selected file type.") );
 
-  QVBoxLayout *rightLayout = new QVBoxLayout();
-  topLayout->addLayout(rightLayout, 3);
-
-  QHBoxLayout *hBox = new QHBoxLayout();
-  rightLayout->addLayout(hBox);
+  // This should work, but places my iconButton centered in the whole dialog..
+  gb = new QGroupBox(i18n("Icon"), this);
+  QHBoxLayout *hBox = new QHBoxLayout(gb,KDialog::marginHint(), KDialog::spacingHint());
+  lay->addWidget(gb,1,3); 
+/*  
+  //This works like a charm:
+  QHBoxLayout *hBox = new QHBoxLayout(this,KDialog::marginHint(), KDialog::spacingHint());
+  lay->addLayout(hBox,1,3); */
 
   iconButton = new KIconLoaderButton(this);
   iconButton->setIconType(KIcon::Desktop, KIcon::MimeType);
   connect(iconButton, SIGNAL(iconChanged(QString)), SLOT(updateIcon(QString)));
-
   iconButton->setFixedSize(50, 50);
-  hBox->addWidget(iconButton);
+  hBox->addWidget(iconButton,AlignLeft);
 
   QWhatsThis::add( iconButton, i18n("This button displays the icon associated"
     " with the selected file type. Click on it to chose a new icon.") );
 
-  QGroupBox *gb = new QGroupBox(i18n("File Patterns"), this);
-  hBox->addWidget(gb);
+  gb = new QGroupBox(i18n("File Patterns"), this);
+  lay->addWidget(gb,3,3);
 
   QGridLayout *grid = new QGridLayout(gb, 3, 2, KDialog::marginHint(),
                                       KDialog::spacingHint());
@@ -115,7 +141,7 @@
   QWhatsThis::add( removeExtButton, i18n("Remove the selected file pattern.") );
 
   gb = new QGroupBox(i18n("Description"), this);
-  rightLayout->addWidget(gb);
+  lay->addWidget(gb,5,3);
 
   gb->setColumnLayout(1, Qt::Horizontal);
   description = new KLineEdit(gb);
@@ -129,7 +155,7 @@
   QWhatsThis::add( description, wtstr );
 
   gb = new QGroupBox(i18n("Application Preference Order"), this);
-  rightLayout->addWidget(gb);
+  lay->addWidget(gb,5,3);
 
   grid = new QGridLayout(gb, 5, 2, KDialog::marginHint(),
                          KDialog::spacingHint());
@@ -170,7 +196,8 @@
 
   QWhatsThis::add( servNewButton, i18n( "Add a new application for this file type." ) );
 
-  wrapper->addStretch(1);
+  left->activate();
+  lay->activate();
 
   init();
 }


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic