Info about some technics in Qt



  • Hi! I want to know:

    1. How to make QSizeGrip placed to the right bottom corner?
    2. How to make the context menu available to the full application?

    Thanks in advance.



  • Inside zip from https://github.com/pehohlva/Tiny_Edit/tree/master/tests
    is a sample from a QCommandLinkButton only swap to normal button ...

      _EpubStart = new StartMenuButton();
        _EpubStart->setMenu(menuTocEpub);
        statusBar()->addWidget(_EpubStart);
        statusBar()->setSizeGripEnabled(false);
    

    0_1505034684465_menuepub.png

    Limit QMenu in one time to display is 30 pieces...



  • @patrik08

    Hi! Thanks, but I don't have QStatusBar to display QSizeGrip.

    I have added QSizeGrip to QGridLayout:

    QSizeGrip *sizeGrip = new QSizeGrip(this);
    QGridLayout *sizeGripLayout = new QGridLayout();
    sizeGripLayout->setContentsMargins(QMargins());
    sizeGripLayout->setSpacing(0);
    sizeGripLayout->addWidget(sizeGrip, 0, 0, 1, 1, Qt::AlignBottom | Qt::AlignRight);
    

    and add QGridLayout to QVBoxLayout (main layout).

    0_1505035408511_2017-09-10_122259.png

    But it adds to much space at the bottom.



  • Or any QWidget have
    http://doc.qt.io/qt-4.8/qwidget.html#contextMenuPolicy-prop
    to place menu..

    QDialog *dialog = new QDialog(0, Qt::FramelessWindowHint);
    QVBoxLayout *layout = new QVBoxLayout(dialog);
    
    // To remove any space between the borders and the QSizeGrip...      
    layout->setContentsMargins(QMargins());         
    // and between the other widget and the QSizeGrip
    layout->setSpacing(0);
    layout->addWidget(new QTextEdit(dialog));
    
    // The QSizeGrip position (here Bottom Right Corner) determines its
    // orientation too
    layout->addWidget(new QSizeGrip(dialog), 0, Qt::AlignBottom | Qt::AlignRight);
    
    dialog->show();
    


  • @patrik08

    Ok. I have changed code to:

    QVBoxLayout *sizeGripLayout = new QVBoxLayout();
    sizeGripLayout->setContentsMargins(QMargins());
    sizeGripLayout->setSpacing(0);
    sizeGripLayout->addWidget(new QSizeGrip(mainWindow), 0, Qt::AlignBottom | Qt::AlignRight); //mainWindow - QWidget
    

    But the same extra space exists at the bottom:
    0_1505037499023_2017-09-10_125728.png

    Also, I have context menu in contextMenuEvent for example in A how to extend it to B? Setting this->setContextMenuPolicy(Qt::CustomContextMenu); at B will not display the context menu from A. Do I need to create the global class to manage context menu everywhere?



  • In QHBoxLayout I have set setContentsMargins(10, 10, 10, 0); - bottom to 0, so:

    0_1505038728294_2017-09-10_131836.png

    I think, it's better, but one problem, when application is maximized, there is no space at the bottom. Should I change setContentsMargins at event or there is other solution?



  • Debug your item for margin and cast element so:

         QObjectList mx = this->children();
          QList<QObject*>::const_iterator x;
          for (x = mx.constBegin(); x != mx.constEnd(); ++x) {
            QObject *fox = *x;
               qDebug() << "name:" << fox->objectName();
               QWidget *vox = qobject_cast<QWidget *>(fox);
               if (vox) {
                  qDebug() << "size element:" << vox->size() << ":" << vox->accessibleName();
    
               }
          }
    


  • @patrik08

    Thanks, but I have changed Qt event and the problem with QSizeGrip has been fixed. The only think now is to create global menu.


  • Lifetime Qt Champion

    Hi,

    Do you mean QMainWindow's menuBar ?



  • I have fixed all issues. Thank you.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.