Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. Italian
  4. Impostare una dimensione di base per QMainWindow
Forum Updated to NodeBB v4.3 + New Features

Impostare una dimensione di base per QMainWindow

Scheduled Pinned Locked Moved Solved Italian
3 Posts 2 Posters 916 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    fermatqt
    wrote on last edited by
    #1

    ciao!

    sto cercando di impostare una dimensione di base dell'80% della risoluzione dello schermo.
    però deve essere possibile ridimensionare la finestra fino ad un minimo.
    quindi non posso usare il setFixedSize.
    ho provato così:

    MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
        QScreen *screen = QGuiApplication::primaryScreen();
        QSize size = screen->availableGeometry().size();
        int width = size.width();
        int height = size.height();
        width *= 0.8;
        height *= 0.8;
        QSize newSize( width, height );
        this->setBaseSize(newSize);
        this->setMinimumWidth(800);
        this->setMinimumHeight(600);
    }
    

    ma a quanto pare quel setBaseSize non funziona.
    come gli posso impostare la dimensione calcolata??

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2
      1. puoi moltiplicare QSize direttamente, no serve scomporre larghezza e altezza
      2. per fare cio' che vuoi non devi impostare setBaseSize ma salvare newSize in una variabile private:, reimplementare sizeHint e ritornare quella variabile

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      0
      • F Offline
        F Offline
        fermatqt
        wrote on last edited by fermatqt
        #3

        ciao!

        nel frattempo ho trovato questa soluzione (ho anche moltiplicato direttamente):

        MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
            QScreen *screen = QGuiApplication::primaryScreen();
            QSize size = screen->availableGeometry().size() * 0.8;
            setGeometry(
                        QStyle::alignedRect(
                            Qt::LeftToRight,
                            Qt::AlignCenter,
                            size,
                            QGuiApplication::primaryScreen()->availableGeometry()
                            )
                        );
            this->setWindowTitle("QRsync");
            this->setMinimumWidth(800);
            this->setMinimumHeight(600);
        }
        

        sembra funzionare!

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved